fish_indent: Fix crash with NUL in the source

Really we should *reject* this
This commit is contained in:
Fabian Boehm 2024-01-10 20:47:39 +01:00
parent 52a3e1393f
commit 50acc4f4de
2 changed files with 9 additions and 3 deletions

View file

@ -521,11 +521,14 @@ impl<'source, 'ast> PrettyPrinterState<'source, 'ast> {
// Unescape the string - this leaves special markers around if there are any
// expansions or anything. We specifically tell it to not compute backslash-escapes
// like \U or \x, because we want to leave them intact.
let mut unescaped = unescape_string(
let Some(mut unescaped) = unescape_string(
input,
UnescapeStringStyle::Script(UnescapeFlags::SPECIAL | UnescapeFlags::NO_BACKSLASHES),
)
.unwrap();
// TODO: If we cannot unescape that means there's something fishy,
// like a NUL in the source.
) else {
return input.into();
};
// Remove INTERNAL_SEPARATOR because that's a quote.
let quote = |ch| ch == INTERNAL_SEPARATOR;

View file

@ -443,3 +443,6 @@ echo a\<\) | $fish_indent
# CHECK: a < )
echo b\|\{ | $fish_indent
# CHECK: b | {
echo "\'\\\\\x00\'" | string unescape | $fish_indent | string escape
# CHECK: \'\\\x00\'