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.
This commit is contained in:
batistalucasv committed 2026-11-12 19:35:12 -03:00
1 parent d30a8392f9
commit 3f7bff9204
2 files changed
+9 -1

No files matched your search

+5
View File
@@ -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)
+4 -1
View File
@@ -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 };