From 3353c5de09db952feb9d4ff76fc398e68172c664 Mon Sep 17 00:00:00 2001 From: RickiNano <81099017+RickiNano@users.noreply.github.com> Date: Fri, 13 Nov 2026 23:10:57 +0100 Subject: [PATCH] File Info: changing the status removes every xmpRights:Marked attribute form it reads (#13821) --- crates/engine/src/cmd/file_cmds/info.rs | 21 ++++++++++++------- .../src/file_info_copyright_title_tests.rs | 21 +++++++++++++++++++ 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/crates/engine/src/cmd/file_cmds/info.rs b/crates/engine/src/cmd/file_cmds/info.rs index 3c9bb37901..0fcbd76359 100644 --- a/crates/engine/src/cmd/file_cmds/info.rs +++ b/crates/engine/src/cmd/file_cmds/info.rs @@ -101,21 +101,22 @@ fn find_attr<'a>(xmp: &'a str, prop: &str) -> Option<(usize, usize, &'a str)> { /// The packet's `xmpRights:Marked` value, as an element or an attribute. fn rights_marked(xmp: &str) -> Option<&str> { - find_element(xmp, "xmpRights:Marked").map(|(_, _, v)| v.trim()).or_else(|| marked_attr(xmp)) + find_element(xmp, "xmpRights:Marked").map(|(_, _, v)| v.trim()).or_else(|| marked_attr(xmp).map(|(_, _, v)| v)) } /// Attribute form `xmpRights:Marked="…"` with either quote, any XML whitespace before the name -/// and around the `=`, as XMP writers lay attributes out on their own lines. -fn marked_attr(xmp: &str) -> Option<&str> { +/// and around the `=`, as XMP writers lay attributes out on their own lines. Returns (start, end, +/// value) with the whitespace before the name in the span, as [`find_attr`] does, so a rewrite +/// removes every form it reads. +fn marked_attr(xmp: &str) -> Option<(usize, usize, &str)> { const NAME: &str = "xmpRights:Marked"; xmp.match_indices(NAME).find_map(|(i, _)| { - if !xmp[..i].ends_with(|c: char| c.is_ascii_whitespace()) { - return None; - } + let start = i.checked_sub(1).filter(|&s| xmp.as_bytes().get(s).is_some_and(u8::is_ascii_whitespace))?; let rest = xmp[i + NAME.len()..].trim_start().strip_prefix('=')?.trim_start(); let quote = rest.chars().next().filter(|&c| c == '"' || c == '\'')?; - let body = &rest[quote.len_utf8()..]; - body.find(quote).map(|end| &body[..end]) + let v0 = xmp.len() - rest.len() + 1; + let v1 = xmp[v0..].find(quote)? + v0; + Some((start, v1 + 1, &xmp[v0..v1])) }) } @@ -298,6 +299,10 @@ pub fn write_file_info(xmp: Option<&str>, info: &Value) -> String { while let Some((a, b, _)) = find_attr(&x, prop) { x.replace_range(a..b, ""); } + // Marked is also read in single quotes or after a tab or newline (#13821). + while let Some((a, b, _)) = (prop == "xmpRights:Marked").then(|| marked_attr(&x)).flatten() { + x.replace_range(a..b, ""); + } } let get = |k: &str| info.get(k).filter(|_| changed(k)).cloned().unwrap_or(Value::Null); let mut body = String::new(); diff --git a/crates/ui-egui/src/file_info_copyright_title_tests.rs b/crates/ui-egui/src/file_info_copyright_title_tests.rs index 101994112a..9040577937 100644 --- a/crates/ui-egui/src/file_info_copyright_title_tests.rs +++ b/crates/ui-egui/src/file_info_copyright_title_tests.rs @@ -80,3 +80,24 @@ fn a_file_opened_with_the_mark_already_set_shows_the_prefix() { assert_eq!(title(&app), want, "{xmp}"); } } + +#[test] +fn changing_the_status_of_an_opened_document_clears_every_attribute_form() { + for attr in ["\n xmpRights:Marked='True'", "\txmpRights:Marked = \"True\"", " xmpRights:Marked=\"True\""] { + let xmp = format!( + r#""# + ); + for steps in [&["unknown"][..], &["publicDomain", "unknown"]] { + let mut app = app(); + std::sync::Arc::make_mut(&mut app.session.active_mut().unwrap().doc).metadata.xmp = Some(xmp.clone().into()); + assert!(title(&app).starts_with("\u{a9} "), "{attr:?}"); + for &s in steps { + status(&mut app, s); + } + assert!(title(&app).starts_with("oracle @ "), "{attr:?} then {steps:?}: {}", title(&app)); + let packet = app.session.documents()[0].doc.metadata.xmp.as_deref().unwrap_or_default().to_string(); + assert!(!packet.contains("xmpRights:Marked"), "{attr:?} then {steps:?} leaves {packet}"); + assert!(packet.contains("rdf:about=\"\""), "the rest of the description stays: {packet}"); + } + } +}