File tree Expand file tree Collapse file tree 1 file changed +3
-4
lines changed
Expand file tree Collapse file tree 1 file changed +3
-4
lines changed Original file line number Diff line number Diff line change @@ -180,9 +180,9 @@ impl Stream {
180180 fn write_str ( & mut self , s : & str ) {
181181 // Future-proof: we may want to use VLQs later.
182182 const MAX_STRING_LENGTH : usize = 127 ;
183- let len = s. len ( ) . min ( MAX_STRING_LENGTH ) ;
183+ let len = s. floor_char_boundary ( MAX_STRING_LENGTH ) ;
184184 self . 0 . write_u8 ( len as u8 ) . expect ( "can't fail" ) ;
185- self . 0 . extend ( & s. as_bytes ( ) [ 0 ..len] ) ; // This may split a character in two. The parser should handle that.
185+ self . 0 . extend ( & s. as_bytes ( ) [ 0 ..len] ) ;
186186 }
187187}
188188
@@ -477,8 +477,7 @@ fn longest_valid_utf8_prefix(data: &[u8]) -> &str {
477477 match std:: str:: from_utf8 ( data) {
478478 Ok ( s) => s,
479479 Err ( error) => {
480- // The string may be been truncated to fit a max length of 255.
481- // This truncation may have happened in the middle of a unicode character.
480+ // Backwards compatibility: old versions could truncate in the middle of a UTF-8 character.
482481 std:: str:: from_utf8 ( & data[ ..error. valid_up_to ( ) ] ) . expect ( "We can trust valid_up_to" )
483482 }
484483 }
You can’t perform that action at this time.
0 commit comments