@@ -94,21 +94,32 @@ public async Task ReadFormAsync_ValueCountLimitMet_Success()
94
94
[ Fact ]
95
95
public async Task ReadFormAsync_ValueCountLimitExceeded_Throw ( )
96
96
{
97
- var bodyPipe = await MakePipeReader ( "foo=1&baz=2&bar=3&baz=4&baf=5" ) ;
97
+ var content = "foo=1&baz=2&bar=3&baz=4&baf=5" ;
98
+ var bodyPipe = await MakePipeReader ( content ) ;
98
99
99
100
var exception = await Assert . ThrowsAsync < InvalidDataException > (
100
101
( ) => ReadFormAsync ( new FormPipeReader ( bodyPipe ) { ValueCountLimit = 3 } ) ) ;
101
102
Assert . Equal ( "Form value count limit 3 exceeded." , exception . Message ) ;
103
+
104
+ // The body pipe is still readable and has not advanced.
105
+ var readResult = await bodyPipe . ReadAsync ( ) ;
106
+ Assert . Equal ( Encoding . UTF8 . GetBytes ( content ) , readResult . Buffer . ToArray ( ) ) ;
102
107
}
103
108
104
109
[ Fact ]
105
110
public async Task ReadFormAsync_ValueCountLimitExceededSameKey_Throw ( )
106
111
{
107
- var bodyPipe = await MakePipeReader ( "baz=1&baz=2&baz=3&baz=4" ) ;
112
+ var content = "baz=1&baz=2&baz=3&baz=4" ;
113
+ var bodyPipe = await MakePipeReader ( content ) ;
108
114
109
115
var exception = await Assert . ThrowsAsync < InvalidDataException > (
110
116
( ) => ReadFormAsync ( new FormPipeReader ( bodyPipe ) { ValueCountLimit = 3 } ) ) ;
111
117
Assert . Equal ( "Form value count limit 3 exceeded." , exception . Message ) ;
118
+
119
+
120
+ // The body pipe is still readable and has not advanced.
121
+ var readResult = await bodyPipe . ReadAsync ( ) ;
122
+ Assert . Equal ( Encoding . UTF8 . GetBytes ( content ) , readResult . Buffer . ToArray ( ) ) ;
112
123
}
113
124
114
125
[ Fact ]
@@ -127,11 +138,16 @@ public async Task ReadFormAsync_KeyLengthLimitMet_Success()
127
138
[ Fact ]
128
139
public async Task ReadFormAsync_KeyLengthLimitExceeded_Throw ( )
129
140
{
130
- var bodyPipe = await MakePipeReader ( "foo=1&baz12345678=2" ) ;
141
+ var content = "foo=1&baz12345678=2" ;
142
+ var bodyPipe = await MakePipeReader ( content ) ;
131
143
132
144
var exception = await Assert . ThrowsAsync < InvalidDataException > (
133
145
( ) => ReadFormAsync ( new FormPipeReader ( bodyPipe ) { KeyLengthLimit = 10 } ) ) ;
134
146
Assert . Equal ( "Form key length limit 10 exceeded." , exception . Message ) ;
147
+
148
+ // The body pipe is still readable and has not advanced.
149
+ var readResult = await bodyPipe . ReadAsync ( ) ;
150
+ Assert . Equal ( Encoding . UTF8 . GetBytes ( content ) , readResult . Buffer . ToArray ( ) ) ;
135
151
}
136
152
137
153
[ Fact ]
@@ -150,11 +166,16 @@ public async Task ReadFormAsync_ValueLengthLimitMet_Success()
150
166
[ Fact ]
151
167
public async Task ReadFormAsync_ValueLengthLimitExceeded_Throw ( )
152
168
{
153
- var bodyPipe = await MakePipeReader ( "foo=1&baz=12345678901" ) ;
169
+ var content = "foo=1&baz=12345678901" ;
170
+ var bodyPipe = await MakePipeReader ( content ) ;
154
171
155
172
var exception = await Assert . ThrowsAsync < InvalidDataException > (
156
173
( ) => ReadFormAsync ( new FormPipeReader ( bodyPipe ) { ValueLengthLimit = 10 } ) ) ;
157
174
Assert . Equal ( "Form value length limit 10 exceeded." , exception . Message ) ;
175
+
176
+ // The body pipe is still readable and has not advanced.
177
+ var readResult = await bodyPipe . ReadAsync ( ) ;
178
+ Assert . Equal ( Encoding . UTF8 . GetBytes ( content ) , readResult . Buffer . ToArray ( ) ) ;
158
179
}
159
180
160
181
// https://en.wikipedia.org/wiki/Percent-encoding
0 commit comments