From ed251578d105681e0b40d7db7f470e90cca8758a Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Wed, 10 Jan 2024 19:33:00 +0100 Subject: [PATCH] fish_indent: Fix crash if errors aren't sorted I've found this for `echo \x1e\<\) | ./fish_indent` Which is *extremely* broken script, to be fair --- fish-rust/src/fish_indent.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fish-rust/src/fish_indent.rs b/fish-rust/src/fish_indent.rs index 389b8e950..2a3011878 100755 --- a/fish-rust/src/fish_indent.rs +++ b/fish-rust/src/fish_indent.rs @@ -471,8 +471,13 @@ impl<'source, 'ast> PrettyPrinterState<'source, 'ast> { fn range_contained_error(&self, r: SourceRange) -> bool { let errs = self.errors.as_ref().unwrap(); let range_is_before = |x: SourceRange, y: SourceRange| x.end().cmp(&y.start()); - assert!(errs.is_sorted_by(|&x, &y| Some(range_is_before(x, y)))); - errs.partition_point(|&range| range_is_before(range, r).is_lt()) != errs.len() + // FIXME: We want to have the errors sorted, but in some cases they aren't. + // I suspect this is when the ast is unwinding because the source is fudged up. + if errs.is_sorted_by(|&x, &y| Some(range_is_before(x, y))) { + errs.partition_point(|&range| range_is_before(range, r).is_lt()) != errs.len() + } else { + false + } } // Emit the gap text before a source range.