Fix touch panics when using invalid timestamp (#6181)

Signed-off-by: nibon7 <nibon7@163.com>
This commit is contained in:
nibon7
2022-07-29 19:41:28 +08:00
committed by GitHub
parent 2cffff0c1b
commit 9e24e452a5
2 changed files with 29 additions and 2 deletions

View File

@ -766,3 +766,20 @@ fn not_create_file_if_it_not_exists() {
assert!(!path.exists());
})
}
#[test]
fn test_invalid_timestamp() {
Playground::setup("test_invalid_timestamp", |dirs, _sandbox| {
let outcome = nu!(
cwd: dirs.test(),
r#"touch -t 20220729. file.txt"#
);
assert!(outcome.err.contains("input has an invalid timestamp"));
let outcome = nu!(
cwd: dirs.test(),
r#"touch -t 20220729120099 file.txt"#
);
assert!(outcome.err.contains("input has an invalid timestamp"));
})
}