File tree 2 files changed +14
-1
lines changed
2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -169,14 +169,14 @@ impl Decoder for LinesCodec {
169
169
Ok ( match self . decode ( buf) ? {
170
170
Some ( frame) => Some ( frame) ,
171
171
None => {
172
+ self . next_index = 0 ;
172
173
// No terminating newline - return remaining data, if any
173
174
if buf. is_empty ( ) || buf == & b"\r " [ ..] {
174
175
None
175
176
} else {
176
177
let line = buf. split_to ( buf. len ( ) ) ;
177
178
let line = without_carriage_return ( & line) ;
178
179
let line = utf8 ( line) ?;
179
- self . next_index = 0 ;
180
180
Some ( line. to_string ( ) )
181
181
}
182
182
}
Original file line number Diff line number Diff line change @@ -62,6 +62,19 @@ fn lines_decoder() {
62
62
assert_eq ! ( None , codec. decode_eof( buf) . unwrap( ) ) ;
63
63
}
64
64
65
+ #[ test]
66
+ fn lines_decoder_invalid_utf8 ( ) {
67
+ let mut codec = LinesCodec :: new ( ) ;
68
+ let buf = & mut BytesMut :: new ( ) ;
69
+ buf. reserve ( 200 ) ;
70
+ buf. put_slice ( b"line 1\xc3 \x28 " ) ;
71
+ assert_eq ! ( None , codec. decode( buf) . unwrap( ) ) ;
72
+ assert ! ( codec. decode_eof( buf) . is_err( ) ) ;
73
+ assert_eq ! ( None , codec. decode_eof( buf) . unwrap( ) ) ;
74
+ buf. put_slice ( b"line 22222222222222\n " ) ;
75
+ assert_eq ! ( "line 22222222222222" , codec. decode( buf) . unwrap( ) . unwrap( ) ) ;
76
+ }
77
+
65
78
#[ test]
66
79
fn lines_decoder_max_length ( ) {
67
80
const MAX_LENGTH : usize = 6 ;
You can’t perform that action at this time.
0 commit comments