use std::collections::BTreeSet;
use std::io::Read;
use serde::{Deserialize, Serialize};
use crate::markup_simplifier::remove_all_rsids;
use crate::namespaces::{W, W15};
use crate::opc::PartFs;
use crate::xmllinq::{Dom, NodeId, XName};
const CORE: &str = "docProps/core.xml";
const APP: &str = "docProps/app.xml";
const CUSTOM: &str = "docProps/custom.xml";
const CUSTOM_REL: &str =
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties";
const CP: &str = "http://schemas.openxmlformats.org/package/2006/metadata/core-properties";
const DC: &str = "http://purl.org/dc/elements/1.1/";
const DCTERMS: &str = "http://purl.org/dc/terms/";
const EXTENDED: &str = "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties";
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ScrubOptions {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub author_alias: Option<String>,
#[serde(default)]
pub rsids: bool,
#[serde(default)]
pub docprops: bool,
#[serde(default)]
pub comments: bool,
}
impl Default for ScrubOptions {
fn default() -> Self {
Self {
author_alias: Some("Author".into()),
rsids: true,
docprops: true,
comments: true,
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ScrubError {
Package(String),
Invalid(String),
}
impl std::fmt::Display for ScrubError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Package(message) => write!(f, "opening DOCX: {message}"),
Self::Invalid(message) => write!(f, "cannot scrub: {message}"),
}
}
}
impl std::error::Error for ScrubError {}
pub fn scrub(docx: &[u8], options: &ScrubOptions) -> Result<Vec<u8>, ScrubError> {
let mut pkg = PartFs::open(docx)
.map_err(|e| ScrubError::Package(crate::opc::refusal_message(docx, &e)))?;
if pkg
.main_document_part()
.is_none_or(|main| pkg.part_bytes(&main).is_none())
{
return Err(ScrubError::Invalid(
"the package has no main document part".into(),
));
}
if let Some(alias) = &options.author_alias
&& (alias.trim().is_empty() || alias.chars().any(char::is_control))
{
return Err(ScrubError::Invalid(
"author_alias must be a nonempty name without control characters".into(),
));
}
let before = crate::validate::validate(docx).map_err(|e| ScrubError::Package(e.to_string()))?;
if options.comments {
remove_comments(&mut pkg);
}
if let Some(alias) = &options.author_alias {
alias_authors(&mut pkg, alias);
}
if options.rsids {
remove_rsids(&mut pkg);
}
if options.docprops {
scrub_properties(&mut pkg);
}
let out = pkg
.to_zip()
.map_err(|e| ScrubError::Package(e.to_string()))?;
let after = crate::validate::validate(&out).map_err(|e| ScrubError::Package(e.to_string()))?;
let new = introduced(&before, &after);
if !new.is_empty() {
return Err(ScrubError::Invalid(format!(
"scrubbing would introduce {}",
new.join(", ")
)));
}
Ok(out)
}
fn introduced(
before: &[crate::validate::Finding],
after: &[crate::validate::Finding],
) -> Vec<String> {
let had = finding_counts(before);
finding_counts(after)
.into_iter()
.filter(|(key, n)| had.get(key).is_none_or(|h| n > h))
.map(|((code, part), _)| format!("{code} in {part}"))
.collect()
}
fn finding_counts(
findings: &[crate::validate::Finding],
) -> std::collections::BTreeMap<(&str, &str), usize> {
let mut counts = std::collections::BTreeMap::new();
for f in findings {
*counts
.entry((f.code.as_str(), f.part.as_str()))
.or_default() += 1;
}
counts
}
struct Part {
name: String,
dom: Dom,
doc: NodeId,
root: NodeId,
}
impl Part {
fn load(pkg: &PartFs, name: &str) -> Option<Self> {
let xml = pkg.part_string(name)?;
let mut dom = Dom::new();
let doc = dom.parse_xdocument(&xml);
let root = dom.root(doc)?;
Some(Self {
name: name.to_string(),
dom,
doc,
root,
})
}
fn store(self, pkg: &mut PartFs) {
pkg.set_part(
&self.name,
self.dom.serialize_document(self.doc).into_bytes(),
);
}
}
fn word_parts(pkg: &PartFs) -> Vec<String> {
pkg.parts()
.into_iter()
.filter(|p| p.starts_with("word/") && p.ends_with(".xml"))
.collect()
}
fn remove_comments(pkg: &mut PartFs) {
let stories: Vec<String> = crate::revision_processor::revision_bearing_parts(pkg)
.into_iter()
.filter(|(_, is_styles)| !is_styles)
.map(|(part, _)| part)
.collect();
for story in &stories {
let Some(mut part) = Part::load(pkg, story) else {
continue;
};
let references = part
.dom
.descendants(part.root, Some(&W::comment_reference()));
if references.is_empty() {
continue;
}
for reference in references {
let run = part
.dom
.parent(reference)
.filter(|&r| part.dom.name_is(r, &W::r()));
part.dom.remove(reference);
if let Some(run) = run
&& part
.dom
.elements(run, None)
.iter()
.all(|&k| part.dom.name_is(k, &W::r_pr()))
{
part.dom.remove(run);
}
}
part.store(pkg);
}
let comments = crate::revision_processor::comments_part(pkg);
crate::revision_processor::prune_orphan_comments(pkg, &stories, comments.as_deref());
}
fn initials(alias: &str) -> String {
alias
.split_whitespace()
.filter_map(|w| w.chars().next())
.flat_map(char::to_uppercase)
.collect()
}
fn alias_authors(pkg: &mut PartFs, alias: &str) {
let author = W::author();
let initials_name = W::name("initials");
let short = initials(alias);
for name in word_parts(pkg) {
if name == "word/people.xml" {
continue;
}
let Some(mut part) = Part::load(pkg, &name) else {
continue;
};
let mut changed = false;
for node in part.dom.descendants_and_self(part.root, None) {
if part
.dom
.attribute(node, &author)
.is_some_and(|a| a != alias)
{
part.dom.set_attribute_value(node, &author, Some(alias));
changed = true;
}
if part
.dom
.attribute(node, &initials_name)
.is_some_and(|i| i != short)
{
part.dom
.set_attribute_value(node, &initials_name, Some(&short));
changed = true;
}
}
if changed {
part.store(pkg);
}
}
let Some(mut people) = Part::load(pkg, "word/people.xml") else {
return;
};
let person = W15::name("person");
let w15_author = W15::name("author");
let mut kept = false;
for p in people.dom.descendants(people.root, Some(&person)) {
if kept {
people.dom.remove(p);
continue;
}
kept = true;
people.dom.set_attribute_value(p, &w15_author, Some(alias));
for presence in people.dom.elements(p, Some(&W15::name("presenceInfo"))) {
people.dom.remove(presence);
}
}
people.store(pkg);
}
fn remove_rsids(pkg: &mut PartFs) {
let rsids = W::name("rsids");
for name in word_parts(pkg) {
if !pkg.part_string(&name).is_some_and(|x| x.contains("rsid")) {
continue;
}
let Some(mut part) = Part::load(pkg, &name) else {
continue;
};
for list in part.dom.descendants(part.root, Some(&rsids)) {
part.dom.remove(list);
}
remove_all_rsids(&mut part.dom, part.root);
part.store(pkg);
}
}
fn remove_children(part: &mut Part, names: &[XName]) -> bool {
let mut changed = false;
for name in names {
for node in part.dom.elements(part.root, Some(name)) {
part.dom.remove(node);
changed = true;
}
}
changed
}
fn scrub_properties(pkg: &mut PartFs) {
if let Some(mut core) = Part::load(pkg, CORE) {
let names = [
XName::get("creator", DC),
XName::get("lastModifiedBy", CP),
XName::get("revision", CP),
XName::get("lastPrinted", CP),
XName::get("created", DCTERMS),
XName::get("modified", DCTERMS),
];
if remove_children(&mut core, &names) {
core.store(pkg);
}
}
if let Some(mut app) = Part::load(pkg, APP) {
let names = [
XName::get("Manager", EXTENDED),
XName::get("Company", EXTENDED),
];
if remove_children(&mut app, &names) {
app.store(pkg);
}
}
if pkg.part_bytes(CUSTOM).is_some() {
pkg.remove_part(CUSTOM);
pkg.remove_package_relationships_by_type(CUSTOM_REL);
pkg.remove_content_type_override(&format!("/{CUSTOM}"));
}
}
pub fn leaks(docx: &[u8], needle: &str) -> Vec<String> {
leaks_within(docx, needle, crate::admission::InputLimits::compare())
}
pub fn leak_scan(docx: &[u8], needle: &str) -> LeakScan {
leak_scan_within(docx, needle, crate::admission::InputLimits::compare())
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum LeakScan {
Complete(Vec<String>),
Incomplete {
part: String,
reason: &'static str,
},
}
impl LeakScan {
fn findings_fail_closed(self) -> Vec<String> {
match self {
Self::Complete(found) => found,
Self::Incomplete { part, reason } => vec![format!("{part} ({reason})")],
}
}
}
pub(crate) fn leaks_within(
docx: &[u8],
needle: &str,
limits: crate::admission::InputLimits,
) -> Vec<String> {
leak_scan_within(docx, needle, limits).findings_fail_closed()
}
fn leak_scan_within(docx: &[u8], needle: &str, limits: crate::admission::InputLimits) -> LeakScan {
let mut found = BTreeSet::new();
if needle.is_empty() {
return LeakScan::Complete(Vec::new());
}
if let Err(error) = crate::admission::preindex_budget(docx, limits) {
return LeakScan::Complete(vec![format!("the package ({error})")]);
}
let mut zip = match crate::opc::open_archive(std::io::Cursor::new(docx)) {
Ok(zip) => zip,
Err(error) => {
return LeakScan::Complete(vec![format!("the package (cannot read: {error})")]);
}
};
let utf16: Vec<u8> = needle.encode_utf16().flat_map(u16::to_le_bytes).collect();
let mut total = 0u64;
for i in 0..zip.len() {
let mut entry = match zip.by_index(i) {
Ok(entry) => entry,
Err(error) => {
found.insert(format!("ZIP entry {i} (cannot read: {error})"));
break;
}
};
let name = match entry.name() {
Ok(name) => name,
Err(error) => {
found.insert(format!("ZIP entry {i} (cannot read name: {error})"));
break;
}
};
let name = crate::admission::shown(&name).into_owned();
if entry.size() > limits.max_part_bytes {
let error = crate::admission::part_declared_over(&name, entry.size(), &limits);
found.insert(format!("{name} ({error})"));
break;
}
let cap = limits
.max_part_bytes
.min(limits.max_uncompressed_bytes.saturating_sub(total));
let mut bytes = Vec::new();
let read = match (&mut entry)
.take(cap.saturating_add(1))
.read_to_end(&mut bytes)
{
Ok(read) => read as u64,
Err(error) => {
found.insert(format!("{name} (cannot read: {error})"));
break;
}
};
if let Err(error) = crate::admission::tally_inflated(&mut total, read, &name, cap, &limits)
{
found.insert(format!("{name} ({error})"));
break;
}
if let Some(reason) = uncertified_encoding(&bytes) {
return LeakScan::Incomplete { part: name, reason };
}
let xml = name.ends_with(".xml") || name.ends_with(".rels");
let hit = if xml {
xml_holds(&xml_text(&bytes), needle)
} else {
contains(&bytes, needle.as_bytes()) || contains(&bytes, &utf16)
};
if hit {
found.insert(name);
}
}
LeakScan::Complete(found.into_iter().collect())
}
fn xml_text(bytes: &[u8]) -> std::borrow::Cow<'_, str> {
let utf16 = bytes
.strip_prefix(&[0xFF, 0xFE])
.or_else(|| bytes.starts_with(b"<\0").then_some(bytes));
match utf16 {
Some(body) => std::borrow::Cow::Owned(
char::decode_utf16(body.chunks(2).map(|pair| {
u16::from_le_bytes([*pair.first().unwrap_or(&0), *pair.get(1).unwrap_or(&0)])
}))
.map(|unit| unit.unwrap_or(char::REPLACEMENT_CHARACTER))
.collect(),
),
None => String::from_utf8_lossy(bytes),
}
}
fn uncertified_encoding(bytes: &[u8]) -> Option<&'static str> {
if bytes.starts_with(&[0x00, 0x00, 0xFE, 0xFF]) {
return Some(
"UTF-32BE is not a certified encoding; this scan reads UTF-8 and UTF-16LE only",
);
}
if bytes.starts_with(&[0xFF, 0xFE, 0x00, 0x00]) {
return Some(
"UTF-32LE is not a certified encoding; this scan reads UTF-8 and UTF-16LE only",
);
}
if bytes.starts_with(&[0xFE, 0xFF]) {
return Some(
"UTF-16BE is not a certified encoding; this scan reads UTF-8 and UTF-16LE only",
);
}
None
}
fn contains(hay: &[u8], needle: &[u8]) -> bool {
!needle.is_empty() && hay.windows(needle.len()).any(|w| w == needle)
}
const NUMERIC_ATTRIBUTES: &[&str] = &[
"id",
"paraId",
"textId",
"durableId",
"w",
"h",
"top",
"bottom",
"left",
"right",
"start",
"end",
"header",
"footer",
"gutter",
"before",
"after",
"line",
"firstLine",
"hanging",
"pos",
"x",
"y",
"cx",
"cy",
"sz",
"space",
"num",
"numId",
"ilvl",
"abstractNumId",
"colFirst",
"colLast",
"percent",
];
fn is_number(value: &str) -> bool {
let digits = value.strip_prefix('-').unwrap_or(value);
!digits.is_empty() && digits.chars().all(|c| c.is_ascii_hexdigit())
}
fn xml_holds(xml: &str, needle: &str) -> bool {
let mut dom = Dom::new();
let doc = dom.parse_xdocument(xml);
let Some(root) = dom.root(doc) else {
return xml.contains(needle);
};
for node in dom.descendant_nodes(doc) {
if dom.is_text(node) || dom.is_comment(node) {
if dom.text_value(node).is_some_and(|v| v.contains(needle)) {
return true;
}
} else if dom.is_pi(node) {
if dom.pi_data(node).is_some_and(|v| v.contains(needle)) {
return true;
}
} else if dom.is_element(node) {
for i in 0..dom.attr_count(node) {
let (name, value) = dom.attr_at(node, i);
if !value.contains(needle) || dom.is_namespace_declaration(name) {
continue;
}
if NUMERIC_ATTRIBUTES.contains(&name.local_name()) && is_number(value) {
continue;
}
return true;
}
}
}
let texts = [W::t(), W::del_text(), W::instr_text()];
for p in dom.descendants_and_self(root, Some(&W::p())) {
let joined: String = dom
.descendants(p, None)
.into_iter()
.filter(|&n| texts.iter().any(|t| dom.name_is(n, t)))
.map(|n| dom.value(n))
.collect();
if joined.contains(needle) {
return true;
}
}
false
}
#[cfg(test)]
#[cfg_attr(all(coverage_nightly, test), coverage(off))]
mod tests {
use super::*;
fn finding(code: &str, part: &str, path: &str) -> crate::validate::Finding {
crate::validate::Finding {
code: code.into(),
set: "word".into(),
severity: "error".into(),
part: part.into(),
location: path.into(),
r#ref: crate::ids::short_paragraph(path),
message: String::new(),
word_fatal: true,
repairable: false,
}
}
#[test]
fn introduced_counts_findings_by_code_and_part_not_path() {
let had = [finding("A", "word/document.xml", "w:body[0]/w:p[3]")];
let moved = [finding("A", "word/document.xml", "w:body[0]/w:p[1]")];
assert!(introduced(&had, &moved).is_empty());
let twice = [moved[0].clone(), finding("A", "word/document.xml", "x")];
assert_eq!(introduced(&had, &twice), ["A in word/document.xml"]);
let other = [
finding("A", "word/comments.xml", ""),
finding("B", "word/document.xml", ""),
];
assert_eq!(
introduced(&had, &other),
["A in word/comments.xml", "B in word/document.xml"]
);
assert!(introduced(&had, &[]).is_empty());
}
#[test]
fn initials_take_the_first_letter_of_each_word() {
assert_eq!(initials("Outside Counsel"), "OC");
assert_eq!(initials("reviewer"), "R");
}
#[test]
fn numbers_and_hex_ids_are_numbers() {
assert!(is_number("1440") && is_number("-720") && is_number("00AB12CD"));
assert!(!is_number("") && !is_number("12 345") && !is_number("Jane"));
}
#[test]
fn a_needle_in_a_numeric_attribute_is_no_leak_but_in_a_text_attribute_it_is() {
let w = W::URI;
let size = format!(r#"<w:document xmlns:w="{w}"><w:pgSz w:w="12240"/></w:document>"#);
assert!(!xml_holds(&size, "1224"));
let alt = format!(r#"<w:document xmlns:w="{w}"><w:x w:val="12240"/></w:document>"#);
assert!(xml_holds(&alt, "1224"));
}
#[test]
fn element_names_are_no_leak() {
let w = W::URI;
let xml = format!(r#"<w:document xmlns:w="{w}"><w:body/></w:document>"#);
assert!(!xml_holds(&xml, "body"));
assert!(xml_holds(&format!("{xml}<!-- body -->"), "body"));
}
}
#[cfg(test)]
#[cfg_attr(all(coverage_nightly, test), coverage(off))]
mod public_memory_leak_boundary_tests {
use super::*;
fn package(body: &str) -> PartFs {
let mut pkg = PartFs::open(include_bytes!(
"../../../tests/fixtures/redline/original.docx"
))
.unwrap();
pkg.set_part("word/document.xml",format!("<w:document xmlns:w='{}'><w:body>{body}<w:sectPr><w:pgSz w:w='12240' w:h='15840'/></w:sectPr></w:body></w:document>",W::URI).into_bytes());
pkg
}
fn snapshot(pkg: &PartFs) -> Vec<(String, Vec<u8>)> {
let mut parts = pkg.parts();
parts.sort();
parts
.into_iter()
.map(|name| {
let bytes = pkg.part_bytes(&name).unwrap().to_vec();
(name, bytes)
})
.collect()
}
#[test]
fn public_leaks_reports_exact_xml_and_binary_part_owners_without_mutating_sources() {
for secret in ["PrivateReviewer", "PendingReviewer"] {
let mut pkg = package("<w:p><w:r><w:t>Independent body payload</w:t></w:r></w:p>");
pkg.set_part(
"customXml/comment.xml",
format!("<metadata><!-- {secret} --></metadata>").into_bytes(),
);
pkg.set_part(
"customXml/pi.xml",
format!("<?privacy {secret}?><metadata/>").into_bytes(),
);
pkg.set_part(
"customXml/attribute.xml",
format!("<metadata id='{secret}'/>").into_bytes(),
);
pkg.set_part(
"customXml/namespace.xml",
format!("<metadata xmlns:private='urn:{secret}'/>").into_bytes(),
);
pkg.set_part("customXml/utf8.bin", secret.as_bytes().to_vec());
pkg.set_part(
"customXml/utf16.bin",
secret.encode_utf16().flat_map(u16::to_le_bytes).collect(),
);
pkg.set_part(
"customXml/clean.bin",
b"Independent binary payload".to_vec(),
);
for part in [
"/customXml/utf8.bin",
"/customXml/utf16.bin",
"/customXml/clean.bin",
] {
pkg.add_content_type_override(part, "application/octet-stream");
}
let original = snapshot(&pkg);
let bytes = pkg.to_zip().unwrap();
let expected = vec![
"customXml/attribute.xml",
"customXml/comment.xml",
"customXml/pi.xml",
"customXml/utf16.bin",
"customXml/utf8.bin",
];
assert_eq!(leaks(&bytes, secret), expected);
assert_eq!(leaks(&bytes, secret), expected);
assert!(leaks(&bytes, "").is_empty());
assert!(leaks(&bytes, "absent reviewer").is_empty());
assert_eq!(snapshot(&PartFs::open(&bytes).unwrap()), original);
}
}
#[test]
fn decoded_entities_and_split_word_runs_are_secrets_but_numeric_ids_are_not() {
let body = "<w:p><w:pPr><w:spacing w:before='1234' w:after='-1234'/></w:pPr><w:r><w:t>Jane </w:t></w:r><w:r><w:rPr><w:b/></w:rPr><w:t>Doe & </w:t></w:r><w:r><w:t>Associates</w:t></w:r></w:p>";
let mut pkg = package(body);
pkg.set_part(
"customXml/encoded.xml",
b"<metadata owner='Jane & Doe'>independent</metadata>".to_vec(),
);
let original = snapshot(&pkg);
let bytes = pkg.to_zip().unwrap();
assert_eq!(
leaks(&bytes, "Jane Doe & Associates"),
["word/document.xml"]
);
assert_eq!(leaks(&bytes, "Jane & Doe"), ["customXml/encoded.xml"]);
assert!(leaks(&bytes, "1234").is_empty());
assert!(leaks(&bytes, "spacing").is_empty());
assert_eq!(snapshot(&PartFs::open(&bytes).unwrap()), original);
}
#[test]
fn invalid_aliases_are_rejected_before_any_source_property_is_rewritten() {
let pkg = package("<w:p><w:r><w:t>Owned source payload</w:t></w:r></w:p>");
let original = snapshot(&pkg);
let bytes = pkg.to_zip().unwrap();
for alias in ["", " ", "Reviewer\nname", "Reviewer\tname"] {
let options = ScrubOptions {
author_alias: Some(alias.into()),
rsids: false,
docprops: false,
comments: false,
};
assert!(
matches!(scrub(&bytes,&options),Err(ScrubError::Invalid(message)) if message=="author_alias must be a nonempty name without control characters")
);
assert_eq!(snapshot(&PartFs::open(&bytes).unwrap()), original);
}
}
}
#[cfg(test)]
#[cfg_attr(all(coverage_nightly, test), coverage(off))]
mod bounded_input_tests {
use super::*;
use crate::admission::{InputLimits, limit_test_support as fixture};
fn refuses(limits: InputLimits, detail: &str) {
let bytes = fixture::package();
let text = leaks_within(&bytes, "absent needle", limits).join(", ");
assert!(text.contains("INPUT_LIMIT"), "{text}");
assert!(text.contains(detail), "{text}");
}
#[test]
fn compressed_limit() {
refuses(fixture::compressed(), "input is");
}
#[test]
fn count_limit() {
refuses(fixture::count(), "3 ZIP entries; the limit is 2");
}
#[test]
fn part_limit() {
refuses(fixture::part(), "a.bin");
}
#[test]
fn aggregate_limit() {
refuses(fixture::total(), "the package limit is 160");
}
#[test]
fn unreadable_entry_is_a_finding() {
let mut bytes = fixture::package();
let cd = bytes.windows(4).position(|w| w == b"PK\x01\x02").unwrap();
bytes[cd + 16] ^= 1;
let findings = leaks_within(&bytes, "absent needle", fixture::limits());
assert!(
!findings.is_empty(),
"an unreadable part cannot certify a redaction"
);
}
#[test]
fn exact_budget_control() {
let bytes = fixture::package();
assert!(leaks_within(&bytes, "absent needle", fixture::limits()).is_empty());
assert_eq!(
leaks_within(&bytes, "aaaa", fixture::limits()),
["word/media/a.bin"]
);
}
}
#[cfg(test)]
#[cfg_attr(all(coverage_nightly, test), coverage(off))]
mod leak_branch_tests {
use super::*;
#[test]
fn only_utf8_and_utf16le_are_certified() {
assert!(
uncertified_encoding(&[0x00, 0x00, 0xFE, 0xFF])
.unwrap()
.starts_with("UTF-32BE")
);
assert!(
uncertified_encoding(&[0xFF, 0xFE, 0x00, 0x00])
.unwrap()
.starts_with("UTF-32LE")
);
assert!(
uncertified_encoding(&[0xFE, 0xFF, 0x00, 0x3C])
.unwrap()
.starts_with("UTF-16BE")
);
assert_eq!(uncertified_encoding(&[0xFF, 0xFE, 0x3C, 0x00]), None);
assert_eq!(uncertified_encoding(b"<x/>"), None);
assert!(!contains(b"abc", b""));
assert!(contains(b"abc", b"bc"));
}
#[test]
fn a_needle_is_found_wherever_xml_can_hold_it() {
assert!(xml_holds("plain text Secret", "Secret"), "not XML");
assert!(xml_holds("<r><!-- Secret --></r>", "Secret"), "comment");
assert!(xml_holds("<r><?pi Secret?></r>", "Secret"), "instruction");
assert!(xml_holds("<r a=\"Secret\"/>", "Secret"), "attribute");
assert!(!xml_holds("<r id=\"1234\"/>", "23"));
assert!(xml_holds("<r name=\"1234\"/>", "23"));
assert!(
!xml_holds("<r xmlns:s=\"urn:Secret\"/>", "Secret"),
"declaration"
);
}
}