Skip to content

Commit d3faece

Browse files
authored
Fix trimming of unicode scope names (#274)
1 parent f4a8b9b commit d3faece

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

puffin/src/data.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)