Fix normalization of strings with overflowing unicode

This commit is contained in:
Joshua Warner 2024-12-15 10:29:01 -08:00
parent 0d182fbd28
commit 4e3df6bde2
No known key found for this signature in database
GPG key ID: 89AD497003F93FDD
6 changed files with 44 additions and 4 deletions

View file

@ -621,8 +621,18 @@ fn normalize_str_segments<'a>(
}
StrSegment::Unicode(t) => {
let hex_code: &str = t.value;
let c = char::from_u32(u32::from_str_radix(hex_code, 16).unwrap()).unwrap();
last_text.push(c);
if let Some(c) = u32::from_str_radix(hex_code, 16)
.ok()
.and_then(char::from_u32)
{
last_text.push(c);
} else {
if !last_text.is_empty() {
let text = std::mem::replace(last_text, String::new_in(arena));
new_segments.push(StrSegment::Plaintext(text.into_bump_str()));
}
new_segments.push(StrSegment::Unicode(Loc::at_zero(t.value)));
}
}
StrSegment::EscapedChar(c) => {
last_text.push(c.unescape());