From 9c3ba4354854415d7a11597dccac6a64fbf1f7a6 Mon Sep 17 00:00:00 2001 From: Leonid Emar-Kar Date: Tue, 29 Apr 2025 12:46:51 +0100 Subject: [PATCH 1/4] update chrono crate version and switch to new_lenient use --- Cargo.lock | 16 ++++++++-------- Cargo.toml | 2 +- src/uu/ls/src/ls.rs | 5 ++--- tests/by-util/test_ls.rs | 10 ++++++++++ 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 15410a4640b..1726193d2ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -304,9 +304,9 @@ checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" [[package]] name = "chrono" -version = "0.4.40" +version = "0.4.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a7964611d71df112cb1730f2ee67324fcf4d0fc6606acbbe9bfe06df124637c" +checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d" dependencies = [ "android-tzdata", "iana-time-zone", @@ -933,7 +933,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -1329,7 +1329,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -2064,7 +2064,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.4.15", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -2077,7 +2077,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.9.4", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -2321,7 +2321,7 @@ dependencies = [ "getrandom 0.3.1", "once_cell", "rustix 1.0.1", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -3783,7 +3783,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.59.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index cde946b68f4..d36248a0ca1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -276,7 +276,7 @@ binary-heap-plus = "0.5.0" bstr = "1.9.1" bytecount = "0.6.8" byteorder = "1.5.0" -chrono = { version = "0.4.38", default-features = false, features = [ +chrono = { version = "0.4.41", default-features = false, features = [ "std", "alloc", "clock", diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 267f6f1c673..a0567f94e8b 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -59,7 +59,6 @@ use uucore::libc::{dev_t, major, minor}; use uucore::line_ending::LineEnding; use uucore::quoting_style::{self, QuotingStyle, escape_name}; use uucore::{ - custom_tz_fmt, display::Quotable, error::{UError, UResult, set_exit_code}, format_usage, @@ -297,8 +296,8 @@ impl TimeStyler { // So it's not yet implemented TimeStyle::Locale => StrftimeItems::new("%b %e %Y").parse(), TimeStyle::Format(fmt) => { - // TODO (#7802): Replace with new_lenient - StrftimeItems::new(custom_tz_fmt::custom_time_format(fmt).as_str()).parse_to_owned() + // Box the fmt value to make it static. + StrftimeItems::new_lenient(Box::leak(fmt.clone().into_boxed_str())).parse() } } .unwrap(); diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index b2d8d961d0d..4517c2bb550 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -5705,3 +5705,13 @@ fn test_time_style_timezone_name() { .succeeds() .stdout_matches(&re_custom_format); } + +#[test] +fn test_unknown_format_specifier() { + let re_custom_format = Regex::new(r"[a-z-]* \d* [\w.]* [\w.]* \d+ \d{4} %0 f\n").unwrap(); + let (at, mut ucmd) = at_and_ucmd!(); + at.touch("f"); + ucmd.args(&["-l", "--time-style=+%Y %0"]) + .succeeds() + .stdout_matches(&re_custom_format); +} From 58eb21222dd33202b11317610f5e69647c5927bd Mon Sep 17 00:00:00 2001 From: Leonid Emar-Kar Date: Tue, 29 Apr 2025 12:56:24 +0100 Subject: [PATCH 2/4] bring back custom_tz_fmt and update test --- src/uu/ls/src/ls.rs | 6 +++++- tests/by-util/test_ls.rs | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index a0567f94e8b..e0ae9e048fc 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -59,6 +59,7 @@ use uucore::libc::{dev_t, major, minor}; use uucore::line_ending::LineEnding; use uucore::quoting_style::{self, QuotingStyle, escape_name}; use uucore::{ + custom_tz_fmt, display::Quotable, error::{UError, UResult, set_exit_code}, format_usage, @@ -297,7 +298,10 @@ impl TimeStyler { TimeStyle::Locale => StrftimeItems::new("%b %e %Y").parse(), TimeStyle::Format(fmt) => { // Box the fmt value to make it static. - StrftimeItems::new_lenient(Box::leak(fmt.clone().into_boxed_str())).parse() + StrftimeItems::new_lenient(Box::leak( + custom_tz_fmt::custom_time_format(fmt).into_boxed_str(), + )) + .parse() } } .unwrap(); diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index 4517c2bb550..f943bc131c7 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -5708,10 +5708,10 @@ fn test_time_style_timezone_name() { #[test] fn test_unknown_format_specifier() { - let re_custom_format = Regex::new(r"[a-z-]* \d* [\w.]* [\w.]* \d+ \d{4} %0 f\n").unwrap(); + let re_custom_format = Regex::new(r"[a-z-]* \d* [\w.]* [\w.]* \d+ \d{4} %0 \d{9} f\n").unwrap(); let (at, mut ucmd) = at_and_ucmd!(); at.touch("f"); - ucmd.args(&["-l", "--time-style=+%Y %0"]) + ucmd.args(&["-l", "--time-style=+%Y %0 %N"]) .succeeds() .stdout_matches(&re_custom_format); } From 6ee97f6af34eeb9b64b3447cdfaafc2339476847 Mon Sep 17 00:00:00 2001 From: Leonid Emar-Kar Date: Tue, 29 Apr 2025 13:08:56 +0100 Subject: [PATCH 3/4] update chrono version in fuzz lock file --- fuzz/Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fuzz/Cargo.lock b/fuzz/Cargo.lock index 43106c423d6..6c5b91281cb 100644 --- a/fuzz/Cargo.lock +++ b/fuzz/Cargo.lock @@ -215,9 +215,9 @@ checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" [[package]] name = "chrono" -version = "0.4.40" +version = "0.4.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a7964611d71df112cb1730f2ee67324fcf4d0fc6606acbbe9bfe06df124637c" +checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d" dependencies = [ "android-tzdata", "iana-time-zone", From 7b8f6748a9ed4e53b7927463813d9c00cbd30d82 Mon Sep 17 00:00:00 2001 From: Leonid Emar-Kar Date: Tue, 29 Apr 2025 13:56:07 +0100 Subject: [PATCH 4/4] replace boxing with parse_to_owned --- src/uu/ls/src/ls.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index e0ae9e048fc..dcfbd3ac346 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -297,11 +297,8 @@ impl TimeStyler { // So it's not yet implemented TimeStyle::Locale => StrftimeItems::new("%b %e %Y").parse(), TimeStyle::Format(fmt) => { - // Box the fmt value to make it static. - StrftimeItems::new_lenient(Box::leak( - custom_tz_fmt::custom_time_format(fmt).into_boxed_str(), - )) - .parse() + StrftimeItems::new_lenient(custom_tz_fmt::custom_time_format(fmt).as_str()) + .parse_to_owned() } } .unwrap();