PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust
M12: a date its data picture can't hold stays ISO in the data
Eric Kaden097c452c84f4
diff --git a/crates/xfa/src/data.rs b/crates/xfa/src/data.rsindex efd2d1848..678b1d975 100644--- a/crates/xfa/src/data.rs+++ b/crates/xfa/src/data.rs@@ -192,10 +192,14 @@ pub(crate) fn data_to_iso(value: &str, data_pattern: Option<&str>) -> String {data_pattern.and_then(|p| pattern_to_iso(value, p)).unwrap_or_else(|| value.to_string())}-/// An ISO date as the data should hold it: in `data_pattern` when the field has one.-fn iso_to_data(iso: String, data_pattern: Option<&str>) -> String {+/// An ISO date as the data should hold it: in `data_pattern` when the field has one and the+/// date reads back from it unchanged (a two-digit year holds only 1950 to 2049), else as ISO.+pub(crate) fn iso_to_data(iso: String, data_pattern: Option<&str>) -> String {match data_pattern {- Some(p) => iso_to_pattern(&iso, p),+ Some(p) => {+ let written = iso_to_pattern(&iso, p);+ if pattern_to_iso(&written, p).as_deref() == Some(iso.as_str()) { written } else { iso }+ }None => iso,}}diff --git a/crates/xfa/src/tests.rs b/crates/xfa/src/tests.rsindex e1b246c6a..0a192479a 100644--- a/crates/xfa/src/tests.rs+++ b/crates/xfa/src/tests.rs@@ -399,6 +399,17 @@ fn node_at<'a>(live: &'a crate::script::FormNode, som: &str) -> Option<&'a cratelive.children.iter().find_map(|c| node_at(c, som))}+#[test]+fn a_date_its_data_picture_cant_hold_is_written_as_iso() {+ use crate::data::{data_to_iso, iso_to_data};+ assert_eq!(iso_to_data("2026-01-02".into(), Some("yymmdd")), "260102");+ // A two-digit year reads back as 1950 to 2049: 2050 and 1949 keep ISO, and read back as written.+ for iso in ["2050-01-02", "1949-12-31"] {+ assert_eq!(iso_to_data(iso.into(), Some("yymmdd")), iso);+ assert_eq!(data_to_iso(iso, Some("yymmdd")), iso);+ }+}+#[test]fn data_fills_the_fields_and_adds_rows() {let form = layout_xml(&template_with_data(1, DATA)).unwrap();diff --git a/parity/acrobat-features.toml b/parity/acrobat-features.tomlindex bcaa3c64b..04d397b90 100644--- a/parity/acrobat-features.toml+++ b/parity/acrobat-features.toml@@ -5244,8 +5244,8 @@ milestone = "M12"status = "partial"commands = ["file.open", "file.save", "form.export_data", "form.import_data"]tools = ["doc_open", "form_fill", "doc_save", "doc_export_data", "doc_import_data", "form_set_image"]-evidence = ["crates/xfa/src/tests.rs::the_datasets_packet_is_written_from_the_fields_and_read_back", "crates/xfa/src/tests.rs::a_date_is_read_from_the_data_in_its_data_picture", "crates/engine/src/tests.rs::xfa_dates_are_written_and_read_back_in_their_data_picture", "crates/engine/src/tests.rs::each_xfa_date_field_is_written_in_its_own_data_picture_and_a_partial_one_keeps_iso", "crates/xfa/src/tests.rs::som_paths_name_the_template_field_their_numbers_count_to", "crates/xfa/src/tests.rs::a_refreshed_field_takes_its_value_from_its_own_template_field", "crates/xfa/src/tests.rs::data_fills_the_fields_and_adds_rows", "crates/engine/src/tests.rs::dynamic_xfa_forms_are_laid_out_on_open_filled_and_saved_incrementally", "crates/xfa/src/tests.rs::data_paths_leave_areas_out", "crates/engine/src/tests.rs::xfa_rows_in_areas_are_laid_out_read_calculated_and_written_where_adobe_binds_them", "crates/xfa/src/tests.rs::data_exports_as_datasets_xml_or_an_xdp_and_imports_from_any_of_them", "crates/xfa/src/tests.rs::a_picture_chosen_for_an_image_field_is_kept_in_the_data_with_its_content_type", "crates/engine/src/tests.rs::xfa_data_exports_imports_and_pictures_round_trip_through_the_session", "crates/engine/src/tests.rs::xfa_data_import_adds_and_removes_rows_of_a_dynamic_form", "crates/automation/tests/automation.rs::xfa_data_files_export_and_import_through_tools"]-notes = "the datasets packet inside the PDF: read on open (values, dates in ISO form, or in the field's data picture (`<bind><picture>`, such as date{YYYYMMDD}) when it has one holding a whole date (one without a day, such as date{YYYYMM}, keeps ISO), each field its own even beside same-named siblings, which saving writes them in too, check and radio states, extra rows for repeating subforms) and rewritten after every form edit from the fields' SOM paths (/PCSom), with areas left out of data paths as Adobe binds them. Export Data writes it as XML (the data alone, rooted at the form's root data node, as Acrobat does) or an XDP with the whole datasets and a reference to the PDF; Import Data takes an XDP, datasets or data XML file (or a bare data document) as the form's whole data, keeping data descriptions, lays a dynamic form out again from it (rows added and removed, more than 50 rows reported) and runs its calculations, undoable; a static form's fields take the data and the rest are emptied; the file's data is re-serialized with the packet's own prefix and every packet rewrite is parsed back before it is written; XFDF/FDF/CSV still go the AcroForm way. Files are UTF-8, UTF-16 or ISO-8859-1, at most 16 MB and 64 levels deep; pictures at most 8 MB (PNG, JPEG, GIF). Pictures chosen for image fields are kept in the data as base64 with xfa:contentType, as Designer saves them. Missing: explicit bind refs, data descriptions are kept but not checked, no data connection (WSDL/ODBC)"+evidence = ["crates/xfa/src/tests.rs::the_datasets_packet_is_written_from_the_fields_and_read_back", "crates/xfa/src/tests.rs::a_date_is_read_from_the_data_in_its_data_picture", "crates/engine/src/tests.rs::xfa_dates_are_written_and_read_back_in_their_data_picture", "crates/engine/src/tests.rs::each_xfa_date_field_is_written_in_its_own_data_picture_and_a_partial_one_keeps_iso", "crates/xfa/src/tests.rs::som_paths_name_the_template_field_their_numbers_count_to", "crates/xfa/src/tests.rs::a_refreshed_field_takes_its_value_from_its_own_template_field", "crates/xfa/src/tests.rs::a_date_its_data_picture_cant_hold_is_written_as_iso", "crates/xfa/src/tests.rs::data_fills_the_fields_and_adds_rows", "crates/engine/src/tests.rs::dynamic_xfa_forms_are_laid_out_on_open_filled_and_saved_incrementally", "crates/xfa/src/tests.rs::data_paths_leave_areas_out", "crates/engine/src/tests.rs::xfa_rows_in_areas_are_laid_out_read_calculated_and_written_where_adobe_binds_them", "crates/xfa/src/tests.rs::data_exports_as_datasets_xml_or_an_xdp_and_imports_from_any_of_them", "crates/xfa/src/tests.rs::a_picture_chosen_for_an_image_field_is_kept_in_the_data_with_its_content_type", "crates/engine/src/tests.rs::xfa_data_exports_imports_and_pictures_round_trip_through_the_session", "crates/engine/src/tests.rs::xfa_data_import_adds_and_removes_rows_of_a_dynamic_form", "crates/automation/tests/automation.rs::xfa_data_files_export_and_import_through_tools"]+notes = "the datasets packet inside the PDF: read on open (values, dates in ISO form, or in the field's data picture (`<bind><picture>`, such as date{YYYYMMDD}) when it has one holding a whole date (one without a day, such as date{YYYYMM}, keeps ISO, as does a date the picture can't hold, such as 2050 in a two-digit year), each field its own even beside same-named siblings, which saving writes them in too, check and radio states, extra rows for repeating subforms) and rewritten after every form edit from the fields' SOM paths (/PCSom), with areas left out of data paths as Adobe binds them. Export Data writes it as XML (the data alone, rooted at the form's root data node, as Acrobat does) or an XDP with the whole datasets and a reference to the PDF; Import Data takes an XDP, datasets or data XML file (or a bare data document) as the form's whole data, keeping data descriptions, lays a dynamic form out again from it (rows added and removed, more than 50 rows reported) and runs its calculations, undoable; a static form's fields take the data and the rest are emptied; the file's data is re-serialized with the packet's own prefix and every packet rewrite is parsed back before it is written; XFDF/FDF/CSV still go the AcroForm way. Files are UTF-8, UTF-16 or ISO-8859-1, at most 16 MB and 64 levels deep; pictures at most 8 MB (PNG, JPEG, GIF). Pictures chosen for image fields are kept in the data as base64 with xfa:contentType, as Designer saves them. Missing: explicit bind refs, data descriptions are kept but not checked, no data connection (WSDL/ODBC)"[[feature]]id = "form.xfa-flatten"