From 3f7bff9204485f10c04444966acfc19f2e5d6419 Mon Sep 17 00:00:00 2001 From: batistalucasv Date: Thu, 12 Nov 2026 19:35:12 -0300 Subject: [PATCH] M2.1: Only inspect the Fit One Page DOCX part by name (#6433) Check the fixed custom XML part name before parsing, so unrelated custom XML stores are not read twice just to look for the fit budget. --- crates/docx/src/fit.rs | 5 +++++ crates/docx/src/read/embed.rs | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/docx/src/fit.rs b/crates/docx/src/fit.rs index 8894800f6b..7d3a1e35ac 100644 --- a/crates/docx/src/fit.rs +++ b/crates/docx/src/fit.rs @@ -18,6 +18,11 @@ pub(crate) const NS: &str = "urn:wordcraft:fit"; /// Marker attribute the parser keeps (namespace declarations are stripped from `El`). const KIND: &str = "wordcraft-fit-v1"; +/// Whether `target` (a relationship target) names our part. +pub(crate) fn is_part(target: &str) -> bool { + target.trim_start_matches('/').eq_ignore_ascii_case(PART) || target.to_ascii_lowercase().ends_with(&format!("/{PART}")) +} + /// Whether `root` is our store (and not a user's custom XML part with a coincidental name). pub(crate) fn is_state(root: &El) -> bool { root.local() == ROOT && root.attr("kind") == Some(KIND) diff --git a/crates/docx/src/read/embed.rs b/crates/docx/src/read/embed.rs index b2e9197961..1e896a632b 100644 --- a/crates/docx/src/read/embed.rs +++ b/crates/docx/src/read/embed.rs @@ -120,6 +120,9 @@ impl Reader<'_> { if ![&rel.kind, &rel.target].iter().all(|s| manifest_field_ok(s)) { continue; } + if crate::fit::is_part(&rel.target) { + continue; + } let root = self.xml(&rel.target).ok().flatten(); if root.as_ref().is_some_and(crate::fit::is_state) { continue; @@ -146,7 +149,7 @@ impl Reader<'_> { /// Read the Fit One Page budget from our custom XML store, if the file has one. pub(super) fn read_fit_state(&mut self, document: &Rels) { for rel in document.list.iter().filter(|r| !r.external && rel_is(&r.kind, rt::CUSTOM_XML)).take(MAX_EMBEDDED_RELS) { - if !manifest_field_ok(&rel.target) { + if !manifest_field_ok(&rel.target) || !crate::fit::is_part(&rel.target) { continue; } let Some(root) = self.xml(&rel.target).ok().flatten() else { continue };