M6: treat imported MaxLen zero as unlimited

This commit is contained in:
djmushin
2026-10-19 22:03:50 -04:00
parent ec0a965074
commit 39d0b953ca
5 changed files with 141 additions and 3 deletions
+4 -1
View File
@@ -754,7 +754,10 @@ fn walk(
inh.q = Some(q);
}
if let Some(m) = d.get(b"MaxLen").and_then(|o| doc.resolve(o).as_int()) {
inh.max_len = usize::try_from(m).ok();
// Compatibility: some writers emit zero for an unlimited text field. Keep /MaxLen
// untouched in the object graph, but expose only positive limits to both UI and API.
// An explicit zero also clears an inherited limit rather than inheriting it again.
inh.max_len = usize::try_from(m).ok().filter(|limit| *limit > 0);
}
let kids: Vec<ObjRef> =
d.get(b"Kids").map(|k| doc.resolve(k)).and_then(|k| k.as_array().cloned()).unwrap_or_default().iter().filter_map(|k| k.as_ref()).collect();
+16
View File
@@ -2239,6 +2239,22 @@ fn page_shapes_closes_only_last_stroked_subpath_but_all_filled_subpaths() {
assert!(filled.rules.is_empty());
}
#[test]
fn zero_max_len_is_unlimited_and_overrides_inherited_limit() {
let mut doc = fixture();
let city = fields(&doc).into_iter().find(|f| f.name == "address.city").unwrap();
let parent = doc.get(city.obj).as_dict().unwrap().get(b"Parent").unwrap().as_ref().unwrap();
doc.update_dict(parent, |d| d.set(b"MaxLen".to_vec(), Object::Int(3))).unwrap();
assert_eq!(fields(&doc).into_iter().find(|f| f.name == "address.city").unwrap().max_len, Some(3));
doc.update_dict(city.obj, |d| d.set(b"MaxLen".to_vec(), Object::Int(0))).unwrap();
assert_eq!(fields(&doc).into_iter().find(|f| f.name == "address.city").unwrap().max_len, None);
set_value(&mut doc, "address.city", &FieldValue::Text("Absalom".into())).unwrap();
let again = reopen(&doc);
assert_eq!(field(&fields(&again), "address.city").value, ["Absalom"]);
assert_eq!(again.get(city.obj).as_dict().unwrap().int(b"MaxLen"), Some(0), "preserve the original entry");
assert!(set_value(&mut doc, "zip", &FieldValue::Text("123456".into())).is_err(), "positive limits still apply");
}
#[test]
fn auto_text_size_fits_single_and_multiline_text() {
use crate::appearance::auto_text_size;