fix(date): handle width overflow in format modifiers

Update `apply_modifiers` to return `Result<String, FormatError>` and check for integer overflow when calculating padding length. This prevents potential panics or incorrect formatting when very large width values are specified. The change adds proper error handling for the "field width too large" case and propagates errors through the formatting pipeline.
This commit is contained in:
mattsu
2026-04-05 10:13:31 +02:00
committed by Sylvestre Ledru
parent 2333e411c7
commit 136b1841b3
2 changed files with 118 additions and 40 deletions
+10
View File
@@ -2507,6 +2507,16 @@ fn test_date_format_modifier_edge_cases() {
}
}
#[test]
fn test_date_format_modifier_huge_width_fails_without_abort() {
let format = format!("+%{}c", usize::MAX);
new_ucmd!()
.arg(&format)
.fails()
.code_is(1)
.stderr_contains("field width too large");
}
// Tests for --debug flag
#[test]
fn test_date_debug_basic() {