Tolerate tokens containing invalid UTF-8

This commit is contained in:
Arthur Baars
2020-11-04 14:46:31 +01:00
parent 8056186c3c
commit c3e8d85f0b

View File

@@ -503,9 +503,7 @@ impl Visitor<'_> {
// Emit a slice of a source file as an Arg.
fn sliced_source_arg(source: &Vec<u8>, n: Node) -> Arg {
let range = n.byte_range();
Arg::String(String::from(
std::str::from_utf8(&source[range.start..range.end]).expect("Failed to decode string"),
))
Arg::String(String::from_utf8_lossy(&source[range.start..range.end]).into_owned())
}
// Emit a pair of `TrapEntry`s for the provided node, appropriately calibrated.