PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust
M6: formattedValue formats only a value of the ISO date's own shape
Eric Kaden526d87d85c94
diff --git a/crates/xfa/src/layout.rs b/crates/xfa/src/layout.rsindex c71f63b40..5a501fbf2 100644--- a/crates/xfa/src/layout.rs+++ b/crates/xfa/src/layout.rs@@ -423,6 +423,12 @@ pub fn formatted_value(picture: &str, raw: &str) -> Option<String> {if !crate::data::date_tokens(&pattern).iter().all(shows) {return None;}+ // Only the ISO date's own shape (`2026-10-20`): `2026-1-2` is not one, and stands.+ let b = raw.as_bytes();+ let iso = b.len() == 10 && b.iter().enumerate().all(|(i, c)| if i == 4 || i == 7 { *c == b'-' } else { c.is_ascii_digit() });+ if !iso {+ return None;+ }let shown = iso_to_pattern(raw, &pattern);(shown != raw).then_some(shown)}diff --git a/crates/xfa/src/tests.rs b/crates/xfa/src/tests.rsindex 0a655dd15..1babcc62f 100644--- a/crates/xfa/src/tests.rs+++ b/crates/xfa/src/tests.rs@@ -354,6 +354,11 @@ fn formatted_values_follow_date_display_pictures() {// Month and weekday names aren't shown yet: the raw value stands rather than `20 mmm 2026`.assert_eq!(crate::formatted_value("date{DD MMM YYYY}", "2026-10-20"), None);assert_eq!(crate::formatted_value("date{EEE MM/DD/YYYY}", "2026-10-20"), None);+ // Only the ISO date's own shape is formatted.+ assert_eq!(crate::formatted_value("date{YYYYMMDD}", "2026-1-2"), None);+ // Parentheses hold the picture's locale and braces its pattern: one without braces has none.+ assert_eq!(crate::formatted_value("date(en_US){YYYYMMDD}", "2026-10-20").as_deref(), Some("20261020"));+ assert_eq!(crate::formatted_value("date(YYYYMMDD)", "2026-10-20"), None);}/// A field's `<format><picture>` is its display picture, kept apart from its `<ui>` edit