File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed
Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -133,8 +133,12 @@ impl ChunkReader {
133133 }
134134 }
135135 Self :: EndCRLF => {
136- if buf. remaining ( ) == CRLF . as_bytes ( ) {
137- buf. set_position ( buf. position ( ) + 2 ) ;
136+ if let Some ( index) = buf
137+ . remaining ( )
138+ . windows ( 2 )
139+ . position ( |window| window == CRLF . as_bytes ( ) )
140+ {
141+ buf. set_position ( index + 2 ) ;
138142 * self = Self :: End ;
139143 Some ( ChunkedBody :: EndCRLF ( buf. split_at_current_pos ( ) ) )
140144 } else {
@@ -492,4 +496,17 @@ pub(crate) mod tests {
492496 let size = ChunkReader :: get_size ( & mut cbuf) . unwrap ( ) ;
493497 assert_eq ! ( size, 7 ) ;
494498 }
499+
500+ #[ test]
501+ fn test_chunked_reader_extra_data ( ) {
502+ let data = "\r \n \
503+ extra data";
504+ let mut buf = BytesMut :: from ( data) ;
505+ let mut cbuf = Cursor :: new ( & mut buf) ;
506+ let mut state = ChunkReader :: EndCRLF ;
507+ let chunk = state. next ( & mut cbuf) . unwrap ( ) ;
508+ assert ! ( matches!( chunk, ChunkedBody :: EndCRLF ( _) ) ) ;
509+ assert_eq ! ( state, ChunkReader :: End ) ;
510+ assert_eq ! ( cbuf. remaining( ) , & b"extra data" [ ..] ) ;
511+ }
495512}
You can’t perform that action at this time.
0 commit comments