mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
date: Catch format string that is not supported by chrono (#4244)
* Catch format string that is not supported by chrono Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
This commit is contained in:
parent
76656aa2c6
commit
81a854a13e
2 changed files with 14 additions and 0 deletions
|
@ -262,6 +262,13 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
Ok(date) => {
|
Ok(date) => {
|
||||||
// GNU `date` uses `%N` for nano seconds, however crate::chrono uses `%f`
|
// GNU `date` uses `%N` for nano seconds, however crate::chrono uses `%f`
|
||||||
let format_string = &format_string.replace("%N", "%f");
|
let format_string = &format_string.replace("%N", "%f");
|
||||||
|
// Refuse to pass this string to chrono as it is crashing in this crate
|
||||||
|
if format_string.contains("%#z") {
|
||||||
|
return Err(USimpleError::new(
|
||||||
|
1,
|
||||||
|
format!("invalid format {}", format_string.replace("%f", "%N")),
|
||||||
|
));
|
||||||
|
}
|
||||||
// Hack to work around panic in chrono,
|
// Hack to work around panic in chrono,
|
||||||
// TODO - remove when a fix for https://github.com/chronotope/chrono/issues/623 is released
|
// TODO - remove when a fix for https://github.com/chronotope/chrono/issues/623 is released
|
||||||
let format_items = StrftimeItems::new(format_string);
|
let format_items = StrftimeItems::new(format_string);
|
||||||
|
|
|
@ -356,6 +356,13 @@ fn test_invalid_format_string() {
|
||||||
assert!(result.stderr_str().starts_with("date: invalid format "));
|
assert!(result.stderr_str().starts_with("date: invalid format "));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_unsupported_format() {
|
||||||
|
let result = new_ucmd!().arg("+%#z").fails();
|
||||||
|
result.no_stdout();
|
||||||
|
assert!(result.stderr_str().starts_with("date: invalid format %#z"));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_date_string_human() {
|
fn test_date_string_human() {
|
||||||
let date_formats = vec![
|
let date_formats = vec![
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue