From 87cd79d6fc54bb4abf07c1e380cd7a9498a78612 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 7 Sep 2016 22:02:07 -0700 Subject: [PATCH] Added decoding tests for the FormReader - This is the first step in work to remove char[] allocations from the FormReader --- .../FormReaderTests.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/Microsoft.AspNetCore.WebUtilities.Tests/FormReaderTests.cs b/test/Microsoft.AspNetCore.WebUtilities.Tests/FormReaderTests.cs index fbe6af6cce..134efbb515 100644 --- a/test/Microsoft.AspNetCore.WebUtilities.Tests/FormReaderTests.cs +++ b/test/Microsoft.AspNetCore.WebUtilities.Tests/FormReaderTests.cs @@ -189,6 +189,23 @@ namespace Microsoft.AspNetCore.WebUtilities Assert.Null(await ReadPair(reader)); } + // https://en.wikipedia.org/wiki/Percent-encoding + [Theory] + [InlineData("++=hello", " ", "hello")] + [InlineData("a=1+1", "a", "1 1")] + [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", "\"%-.<>\\^_`{|}~", "\"%-.<>\\^_`{|}~")] + [InlineData("a=%41", "a", "A")] // ascii encoded hex + [InlineData("a=%C3%A1", "a", "\u00e1")] // utf8 code points + [InlineData("a=%u20AC", "a", "%u20AC")] // utf16 not supported + public async Task ReadForm_Decoding(string formData, string key, string expectedValue) + { + var body = MakeStream(bufferRequest: false, text: formData); + + var form = await ReadFormAsync(new FormReader(body)); + + Assert.Equal(expectedValue, form[key]); + } + protected virtual Task> ReadFormAsync(FormReader reader) { return Task.FromResult(reader.ReadForm());