File tree 2 files changed +8
-3
lines changed
2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -83,6 +83,9 @@ header! {
83
83
test_header!( test14,
84
84
vec![ b"matched-\" dquotes\" " ] ,
85
85
None :: <ETag >) ;
86
+ test_header!( test15,
87
+ vec![ b"\" " ] ,
88
+ None :: <ETag >) ;
86
89
}
87
90
}
88
91
Original file line number Diff line number Diff line change @@ -123,15 +123,17 @@ impl FromStr for EntityTag {
123
123
let length: usize = s. len ( ) ;
124
124
let slice = & s[ ..] ;
125
125
// Early exits if it doesn't terminate in a DQUOTE.
126
- if !slice. ends_with ( '"' ) {
126
+ if !slice. ends_with ( '"' ) || slice . len ( ) < 2 {
127
127
return Err ( :: Error :: Header ) ;
128
128
}
129
129
// The etag is weak if its first char is not a DQUOTE.
130
- if slice. starts_with ( '"' ) && check_slice_validity ( & slice[ 1 ..length-1 ] ) {
130
+ if slice. len ( ) >= 2 && slice. starts_with ( '"' )
131
+ && check_slice_validity ( & slice[ 1 ..length-1 ] ) {
131
132
// No need to check if the last char is a DQUOTE,
132
133
// we already did that above.
133
134
return Ok ( EntityTag { weak : false , tag : slice[ 1 ..length-1 ] . to_owned ( ) } ) ;
134
- } else if slice. starts_with ( "W/\" " ) && check_slice_validity ( & slice[ 3 ..length-1 ] ) {
135
+ } else if slice. len ( ) >= 4 && slice. starts_with ( "W/\" " )
136
+ && check_slice_validity ( & slice[ 3 ..length-1 ] ) {
135
137
return Ok ( EntityTag { weak : true , tag : slice[ 3 ..length-1 ] . to_owned ( ) } ) ;
136
138
}
137
139
Err ( :: Error :: Header )
You can’t perform that action at this time.
0 commit comments