mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-21 04:39:39 +08:00
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
This commit is contained in:
parent
76ddfca420
commit
ed251578d1
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user