From b5ccacf5b57b79849ed762f5024141a884b69a00 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Wed, 10 Jan 2024 18:54:25 +0100 Subject: [PATCH] fish_indent: Fix crash with redirection at the end of the source --- fish-rust/src/fish_indent.rs | 12 ++++++++++-- tests/checks/indent.fish | 3 +++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/fish-rust/src/fish_indent.rs b/fish-rust/src/fish_indent.rs index cbd77a97b..389b8e950 100755 --- a/fish-rust/src/fish_indent.rs +++ b/fish-rust/src/fish_indent.rs @@ -614,9 +614,17 @@ impl<'source, 'ast> PrettyPrinterState<'source, 'ast> { fn visit_redirection(&mut self, node: &ast::Redirection) { // No space between a redirection operator and its target (#2899). - self.emit_text(node.oper.range().unwrap(), GapFlags::default()); + let Some(orange) = node.oper.range() else { + return; + }; + self.emit_text(orange, GapFlags::default()); + + // (target is None if the source ends in a `<` or `>` + let Some(trange) = node.target.range() else { + return; + }; self.emit_text( - node.target.range().unwrap(), + trange, GapFlags { skip_space: true, ..Default::default() diff --git a/tests/checks/indent.fish b/tests/checks/indent.fish index d11ae21d7..f406278a3 100644 --- a/tests/checks/indent.fish +++ b/tests/checks/indent.fish @@ -435,3 +435,6 @@ echo $status #CHECK: 0 echo 'PATH={$PATH[echo " "' | $fish_indent --ansi # CHECK: PATH={$PATH[echo " " + +echo a\> | $fish_indent +# CHECK: a >