mirror of
https://github.com/nushell/nushell.git
synced 2024-11-25 01:43:47 +01:00
Fix a panic when parsing empty file (#11314)
The previous implementation presumed that if files were given, they had contents. The change makes the fallback to permanent files uniform. Fix #11256
This commit is contained in:
parent
3633772d52
commit
fb7f6fc08b
@ -355,11 +355,10 @@ impl<'a> StateWorkingSet<'a> {
|
|||||||
return &contents[begin..end];
|
return &contents[begin..end];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return self.permanent_state.get_span_contents(span);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
panic!("internal error: missing span contents in file cache")
|
// if no files with span were found, fall back on permanent ones
|
||||||
|
return self.permanent_state.get_span_contents(span);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn enter_scope(&mut self) {
|
pub fn enter_scope(&mut self) {
|
||||||
|
@ -329,3 +329,14 @@ fn main_script_can_have_subcommands2() {
|
|||||||
assert!(actual.out.contains("usage: script.nu"));
|
assert!(actual.out.contains("usage: script.nu"));
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn source_empty_file() {
|
||||||
|
Playground::setup("source_empty_file", |dirs, sandbox| {
|
||||||
|
sandbox.mkdir("source_empty_file");
|
||||||
|
sandbox.with_files(vec![FileWithContent("empty.nu", "")]);
|
||||||
|
|
||||||
|
let actual = nu!(cwd: dirs.test(), pipeline("nu empty.nu"));
|
||||||
|
assert!(actual.out.is_empty());
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user