fix(anatomy): V1-2.2 glued url( removed everywhere, Figma exports, mask units
The reader removes any attribute holding a url( that url_openings does not read, so reader, verdict, preview, canvas and PDF view accept the same drawings. maskUnits, maskContentUnits, clipPathUnits allowed with their two keywords (owner go). The owner's two raw Figma exports committed as fixtures with fixed expectations.
This commit is contained in:
1 parent
98060d74a3
commit
7d9ab8cf2f
11 files changed
+299
-13
No files matched your search
@@ -413,6 +413,126 @@ fn every_url_spelling_but_the_strict_one_is_refused() {
|
||||
);
|
||||
}
|
||||
|
||||
/// Final review 2026-10-30: the one `url(` grammar holds in every attribute, not only in the
|
||||
/// presentation ones. A `url(` glued to a longer name, however spelt, is removed wherever it
|
||||
/// stands; a non-strict `url(` is active content; a reference to an absent id is refused; a
|
||||
/// strict reference and a value with no `url(` are kept.
|
||||
#[test]
|
||||
fn every_attribute_reads_url_with_the_one_grammar() {
|
||||
let svg = |attr: &str, value: &str| {
|
||||
format!(
|
||||
"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 10 10\">\
|
||||
<linearGradient id=\"a\"/><g {attr}=\"{value}\"><path d=\"M0 0\"/></g></svg>"
|
||||
)
|
||||
};
|
||||
for attr in ["class", "result", "values", "transform", "in", "type"] {
|
||||
for value in [
|
||||
"xurl(#a)",
|
||||
"-url(#a)",
|
||||
"_url(#a)",
|
||||
"9url(#a)",
|
||||
"éurl(#a)",
|
||||
"\u{a0}url(#a)",
|
||||
"xurl(#a)",
|
||||
"xURL(#a)",
|
||||
"url(#a) xurl(#a)",
|
||||
] {
|
||||
let cleaning = clean_svg(svg(attr, value).as_bytes());
|
||||
assert_eq!(outcome(&cleaning), (Cleanable, None), "{attr}={value}");
|
||||
assert_eq!(cleaning.removed, [format!("g@{attr}")], "{attr}={value}");
|
||||
assert_fixpoint(cleaning.stored.as_deref().unwrap());
|
||||
}
|
||||
for value in [
|
||||
"url(#%61)",
|
||||
"url('#\ta')",
|
||||
"url(#a",
|
||||
"\\75rl(#a)",
|
||||
"u\\72l(#a)",
|
||||
] {
|
||||
let cleaning = clean_svg(svg(attr, value).as_bytes());
|
||||
assert_eq!(
|
||||
outcome(&cleaning),
|
||||
(Rejected, Some("svg_active_content")),
|
||||
"{attr}={value}"
|
||||
);
|
||||
}
|
||||
assert_eq!(
|
||||
outcome(&clean_svg(svg(attr, "url(#nope)").as_bytes())),
|
||||
(Rejected, Some("dangling_reference")),
|
||||
"{attr}"
|
||||
);
|
||||
for value in ["url(#a)", "URL( '#a' )", "curl", "url", "a(b)", "M0 0"] {
|
||||
assert_eq!(
|
||||
outcome(&clean_svg(svg(attr, value).as_bytes())),
|
||||
(Clean, None),
|
||||
"{attr}={value}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Owner decision 2026-10-30 (Figma writes `maskUnits="userSpaceOnUse"`): the three unit
|
||||
/// attributes of masks and clip paths are kept with their two keywords only.
|
||||
#[test]
|
||||
fn mask_and_clip_units_keep_their_keywords_only() {
|
||||
for attr in ["maskUnits", "maskContentUnits", "clipPathUnits"] {
|
||||
for value in ["userSpaceOnUse", "objectBoundingBox"] {
|
||||
let svg = format!(
|
||||
"<svg xmlns=\"http://www.w3.org/2000/svg\"><mask id=\"m\" {attr}=\"{value}\"/></svg>"
|
||||
);
|
||||
assert_eq!(
|
||||
outcome(&clean_svg(svg.as_bytes())),
|
||||
(Clean, None),
|
||||
"{attr}={value}"
|
||||
);
|
||||
}
|
||||
for value in ["", " userSpaceOnUse", "userspaceonuse", "url(#m)", "x(1)"] {
|
||||
let svg = format!(
|
||||
"<svg xmlns=\"http://www.w3.org/2000/svg\"><mask id=\"m\" {attr}=\"{value}\"/></svg>"
|
||||
);
|
||||
let cleaning = clean_svg(svg.as_bytes());
|
||||
assert_eq!(cleaning.outcome, Cleanable, "{attr}={value}");
|
||||
assert_eq!(cleaning.removed, [format!("mask@{attr}")], "{attr}={value}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The owner's Figma exports (2026-10-30, the frame of `inkscape-source.svg`, raw files): the
|
||||
/// clip path written as a luminance `mask` in user space, the dashed stroke expanded into path
|
||||
/// segments, the ellipse and the rectangle as paths, `fill="none"` on the root, the gradient
|
||||
/// after its use in `defs`. `ids` adds layer names as ids, some with spaces (`Clip path group`),
|
||||
/// which the id grammar removes; nothing names them. The live text is in neither file.
|
||||
#[test]
|
||||
fn the_figma_exports_keep_their_mask_gradient_and_shapes() {
|
||||
let cases: [(&str, CleaningOutcome, &[&str]); 2] = [
|
||||
("figma-web-20261030-default.svg", Clean, &[]),
|
||||
("figma-web-20261030-ids.svg", Cleanable, &["g@id"]),
|
||||
];
|
||||
for (file, expected, removed) in cases {
|
||||
let cleaning = clean_svg(&fixture(&format!("exports/owner/{file}")));
|
||||
assert_eq!(outcome(&cleaning), (expected, None), "{file}");
|
||||
assert_eq!(cleaning.removed, removed, "{file}");
|
||||
assert!(
|
||||
cleaning.active.is_empty() && !cleaning.style_removed,
|
||||
"{file}"
|
||||
);
|
||||
let stored = cleaning.stored.as_deref().unwrap();
|
||||
for kept in [
|
||||
"maskUnits=\"userSpaceOnUse\"",
|
||||
"style=\"mask-type:luminance\"",
|
||||
"mask=\"url(#mask0_3_9)\"",
|
||||
"fill=\"url(#paint0_linear_3_9)\"",
|
||||
"gradientUnits=\"userSpaceOnUse\"",
|
||||
"stop-opacity=\"0.8\"",
|
||||
"fill-opacity=\"0.5\"",
|
||||
] {
|
||||
assert!(stored.contains(kept), "{file}: {kept}");
|
||||
}
|
||||
assert!(!stored.contains("<text"), "{file}");
|
||||
assert_fixpoint(stored);
|
||||
}
|
||||
}
|
||||
|
||||
/// Real Inkscape 1.4.3 exports (owner go 2026-10-29; `exports/generate-inkscape.sh`): its
|
||||
/// editor metadata and namespaces and the `text` it keeps as text are removed and named, so
|
||||
/// each is cleanable; shapes, gradient, clip path, internal references and colours stay; the
|
||||
|
||||
Reference in new issue
Block a user