public void ReadUtf8Data() { var buffer = new ReadOnlySequence <byte>(_singleUtf8); KeyValueAccumulator accum = default; _formPipeReader.ParseFormValues(ref buffer, ref accum, isFinalBlock: true); }
public void TryParseFormValues_MultiSegmentExceedValueLengthThrowsInSplitSegmentEnd() { var readOnlySequence = ReadOnlySequenceFactory.CreateSegments(Encoding.UTF8.GetBytes("foo=ba&baz=bo"), Encoding.UTF8.GetBytes("o&t=asdfasdfasd")); KeyValueAccumulator accumulator = default; var formReader = new FormPipeReader(null); formReader.ValueLengthLimit = 10; var exception = Assert.Throws <InvalidDataException>(() => formReader.ParseFormValues(ref readOnlySequence, ref accumulator, isFinalBlock: true)); Assert.Equal("Form value length limit 10 exceeded.", exception.Message); }
public void TryParseFormValues_MultiSegmentExceedKeyLengthThrows() { var readOnlySequence = ReadOnlySequenceFactory.SingleSegmentFactory.CreateWithContent(Encoding.UTF8.GetBytes("foo=bar&baz=boo&t=")); KeyValueAccumulator accumulator = default; var formReader = new FormPipeReader(null); formReader.KeyLengthLimit = 2; var exception = Assert.Throws <InvalidDataException>(() => formReader.ParseFormValues(ref readOnlySequence, ref accumulator, isFinalBlock: true)); Assert.Equal("Form key length limit 2 exceeded.", exception.Message); }
public void TryParseFormValues_SingleSegmentWorks(Encoding encoding) { var readOnlySequence = new ReadOnlySequence <byte>(encoding.GetBytes("foo=bar&baz=boo")); KeyValueAccumulator accumulator = default; var formReader = new FormPipeReader(null, encoding); formReader.ParseFormValues(ref readOnlySequence, ref accumulator, isFinalBlock: true); Assert.Equal(2, accumulator.KeyCount); var dict = accumulator.GetResults(); Assert.Equal("bar", dict["foo"]); Assert.Equal("boo", dict["baz"]); }
public void TryParseFormValues_MultiSegmentSplitAcrossSegmentsThatNeedDecodingWorks(Encoding encoding) { var readOnlySequence = ReadOnlySequenceFactory.SingleSegmentFactory.CreateWithContent(encoding.GetBytes("\"%-.<>\\^_`{|}~=\"%-.<>\\^_`{|}~&\"%-.<>\\^_`{|}=wow")); KeyValueAccumulator accumulator = default; var formReader = new FormPipeReader(null, encoding); formReader.ParseFormValues(ref readOnlySequence, ref accumulator, isFinalBlock: true); Assert.Equal(2, accumulator.KeyCount); var dict = accumulator.GetResults(); Assert.Equal("\"%-.<>\\^_`{|}~", dict["\"%-.<>\\^_`{|}~"]); Assert.Equal("wow", dict["\"%-.<>\\^_`{|}"]); }
public void TryParseFormValues_MultiSegmentWithArrayPoolAcrossSegmentsWorks(Encoding encoding) { var readOnlySequence = ReadOnlySequenceFactory.SingleSegmentFactory.CreateWithContent(encoding.GetBytes("foo=bar&baz=bo" + new string('a', 128))); KeyValueAccumulator accumulator = default; var formReader = new FormPipeReader(null, encoding); formReader.ParseFormValues(ref readOnlySequence, ref accumulator, isFinalBlock: true); Assert.Equal(2, accumulator.KeyCount); var dict = accumulator.GetResults(); Assert.Equal("bar", dict["foo"]); Assert.Equal("bo" + new string('a', 128), dict["baz"]); }
public void TryParseFormValues_DecodedPlusesWorks(Encoding encoding) { var readOnlySequence = ReadOnlySequenceFactory.SingleSegmentFactory.CreateWithContent(encoding.GetBytes("++%2B=+++%2B&++++=++++&+=")); KeyValueAccumulator accumulator = default; var formReader = new FormPipeReader(null, encoding); formReader.ParseFormValues(ref readOnlySequence, ref accumulator, isFinalBlock: true); Assert.Equal(3, accumulator.KeyCount); var dict = accumulator.GetResults(); Assert.Equal(" ", dict[" "]); Assert.Equal(" +", dict[" +"]); Assert.Equal("", dict[" "]); }