File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -208,18 +208,9 @@ impl<'a> From<&'a EntityTag> for HeaderValue {
208208/// 2. in the range `%x23` to `%x7E`, or
209209/// 3. above `%x80`
210210fn check_slice_validity ( slice : & [ u8 ] ) -> bool {
211- slice. iter ( ) . all ( |& c| {
212- // HeaderValue already validates that this doesnt contain control
213- // characters, so we only need to look for DQUOTE (`"`).
214- //
215- // The debug_assert is just in case we use check_slice_validity in
216- // some new context that didnt come from a HeaderValue.
217- debug_assert ! (
218- ( b'\x21' ..=b'\x7e' ) . contains( & c) | ( c >= b'\x80' ) ,
219- "EntityTag expects HeaderValue to have check for control characters"
220- ) ;
221- c != b'"'
222- } )
211+ slice
212+ . iter ( )
213+ . all ( |& c| c == b'\x21' || ( b'\x23' ..=b'\x7e' ) . contains ( & c) || c >= b'\x80' )
223214}
224215
225216// ===== impl EntityTagRange =====
@@ -307,6 +298,20 @@ mod tests {
307298 fails ! ( b"\" unmatched-dquotes1" ) ;
308299 fails ! ( b"unmatched-dquotes2\" " ) ;
309300 fails ! ( b"\" inner\" quotes\" " ) ;
301+ fails ! ( b"\" contains space\" " ) ;
302+ fails ! ( b"W/\" contains space\" " ) ;
303+ fails ! ( b"\" contains\t tab\" " ) ;
304+ }
305+
306+ #[ test]
307+ fn test_etag_from_str_rejects_whitespace ( ) {
308+ for value in & [
309+ "\" contains space\" " ,
310+ "W/\" contains space\" " ,
311+ "\" contains\t tab\" " ,
312+ ] {
313+ assert ! ( value. parse:: <crate :: ETag >( ) . is_err( ) ) ;
314+ }
310315 }
311316
312317 /*
You can’t perform that action at this time.
0 commit comments