fish_indent: Fix crash with redirection at the end of the source

This commit is contained in:
Fabian Boehm 2024-01-10 18:54:25 +01:00
parent cb51b236f3
commit b5ccacf5b5
2 changed files with 13 additions and 2 deletions

View File

@ -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()

View File

@ -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 >