Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Commit 87cd79d

Browse files
committed
Added decoding tests for the FormReader
- This is the first step in work to remove char[] allocations from the FormReader
1 parent 18f08fd commit 87cd79d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

test/Microsoft.AspNetCore.WebUtilities.Tests/FormReaderTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,23 @@ public async Task ReadNextPair_ReturnsNullOnEmptyStream(bool bufferRequest)
189189
Assert.Null(await ReadPair(reader));
190190
}
191191

192+
// https://en.wikipedia.org/wiki/Percent-encoding
193+
[Theory]
194+
[InlineData("++=hello", " ", "hello")]
195+
[InlineData("a=1+1", "a", "1 1")]
196+
[InlineData("%22%25%2D%2E%3C%3E%5C%5E%5F%60%7B%7C%7D%7E=%22%25%2D%2E%3C%3E%5C%5E%5F%60%7B%7C%7D%7E", "\"%-.<>\\^_`{|}~", "\"%-.<>\\^_`{|}~")]
197+
[InlineData("a=%41", "a", "A")] // ascii encoded hex
198+
[InlineData("a=%C3%A1", "a", "\u00e1")] // utf8 code points
199+
[InlineData("a=%u20AC", "a", "%u20AC")] // utf16 not supported
200+
public async Task ReadForm_Decoding(string formData, string key, string expectedValue)
201+
{
202+
var body = MakeStream(bufferRequest: false, text: formData);
203+
204+
var form = await ReadFormAsync(new FormReader(body));
205+
206+
Assert.Equal(expectedValue, form[key]);
207+
}
208+
192209
protected virtual Task<Dictionary<string, StringValues>> ReadFormAsync(FormReader reader)
193210
{
194211
return Task.FromResult(reader.ReadForm());

0 commit comments

Comments
 (0)