Skip to content

Commit 999137f

Browse files
committed
fix: ETag should not debug assert values don't have spaces
1 parent 50bfa1e commit 999137f

1 file changed

Lines changed: 17 additions & 12 deletions

File tree

‎src/util/entity.rs‎

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff 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`
210210
fn 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\ttab\"");
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\ttab\"",
312+
] {
313+
assert!(value.parse::<crate::ETag>().is_err());
314+
}
310315
}
311316

312317
/*

0 commit comments

Comments
 (0)