From 50acc4f4de2d311bcc4a1ec506bc97a26020b4d5 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Wed, 10 Jan 2024 20:47:39 +0100 Subject: [PATCH] fish_indent: Fix crash with NUL in the source Really we should *reject* this --- fish-rust/src/fish_indent.rs | 9 ++++++--- tests/checks/indent.fish | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/fish-rust/src/fish_indent.rs b/fish-rust/src/fish_indent.rs index c8a36938d..8a4ee5cfc 100755 --- a/fish-rust/src/fish_indent.rs +++ b/fish-rust/src/fish_indent.rs @@ -521,11 +521,14 @@ fn clean_text(&self, input: &wstr) -> WString { // 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; diff --git a/tests/checks/indent.fish b/tests/checks/indent.fish index 3f2f3d5f1..5368a93c8 100644 --- a/tests/checks/indent.fish +++ b/tests/checks/indent.fish @@ -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\'