Ignore Shift JIS decoding errors in Fst::get_name

This commit is contained in:
Luke Street 2024-10-18 00:02:37 -06:00
parent be4672471d
commit d4bca2caa8
1 changed files with 3 additions and 4 deletions

View File

@ -119,10 +119,9 @@ impl<'a> Fst<'a> {
let c_string = CStr::from_bytes_until_nul(name_buf).map_err(|_| { let c_string = CStr::from_bytes_until_nul(name_buf).map_err(|_| {
format!("FST: name at offset {} not null-terminated", node.name_offset()) format!("FST: name at offset {} not null-terminated", node.name_offset())
})?; })?;
let (decoded, _, errors) = SHIFT_JIS.decode(c_string.to_bytes()); let (decoded, _, _) = SHIFT_JIS.decode(c_string.to_bytes());
if errors { // Ignore decoding errors, we can't do anything about them. Consumers may check for
return Err(format!("FST: Failed to decode name at offset {}", node.name_offset())); // U+FFFD (REPLACEMENT CHARACTER), or fetch the raw bytes from the string table.
}
Ok(decoded) Ok(decoded)
} }