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:
bchanot committed 2026-10-30 15:05:56 +01:00
1 parent 98060d74a3
commit 7d9ab8cf2f
11 files changed
+299 -13

No files matched your search

+20 -2
View File
@@ -30,5 +30,23 @@ covered above by a real 1.4.3 export). The owner opens `inkscape-source.svg` in
exports it unchanged and puts the files in `owner/`, named `<tool>-<version>-<date>-<variant>.svg`;
`owner/README.md` gives the exact steps. The suite reads every file there: each must be refused
(with a closed reason) or cleaned into a stored form that reads back with no removal, and a file
whose name contains `-active-` must be refused for active content. Until files arrive, that test
runs on an empty folder and A6 stays open.
whose name contains `-active-` must be refused for active content. A6 (owner, 2026-10-30)
requires Figma and the real Adobe Illustrator; Affinity is optional. Status: Figma committed
and passing, Illustrator awaited, so A6 stays open.
| File | Tool | Expected |
|---|---|---|
| `owner/figma-web-20261030-default.svg` | Figma in the browser (no version shown), exported by the owner on 2026-10-30, raw | clean, nothing removed |
| `owner/figma-web-20261030-ids.svg` | same, « Include "id" attribute » | cleanable: `g@id` (layer names with spaces, `Clip path group`, outside the id grammar; nothing names them) |
What Figma writes, as read in these two files: the drawing is the 180 × 130 frame Figma made
from the source's clip rectangle (coordinates shifted by 10); the clip path becomes a
`<mask style="mask-type:luminance" maskUnits="userSpaceOnUse">` holding a white rectangle,
applied by `mask="url(#mask0_3_9)"`; the dashed stroke is expanded into one path of dash
segments (no `stroke-dasharray`); the ellipse and the rounded rectangle are paths;
`fill="none"` sits on the root; the gradient is in a `defs` written after its use,
`gradientUnits="userSpaceOnUse"`, colours in uppercase hex. Neither file carries the live
text « Garrot », as text or as outlines, so Figma's handling of text is not covered by these
fixtures. Kept by the owner's decision of 2026-10-30: `maskUnits` (removing it re-read the
mask region in bounding-box units and cut half a stroke at (10, 100) in Chromium 156); the
stored forms render pixel-identical to the raw files (Chromium 156, × 8).
+7 -1
View File
@@ -17,6 +17,9 @@ differently, and I could not check them here.
## Illustrator (Fichier › Ouvrir… `inkscape-source.svg`)
Required for A6 (owner, 2026-10-30), and only from the real Adobe Illustrator:
VectorCraft or another look-alike is not equivalent.
1. File › Export › Export As… › format SVG, « Use Artboards » ticked.
2. SVG Options, two exports of the same drawing:
- `…-presentation.svg`: Styling « Presentation Attributes », Font « SVG »
@@ -30,13 +33,16 @@ differently, and I could not check them here.
## Figma (import `inkscape-source.svg` into a file, or drag it onto the canvas)
Done on 2026-10-30: `figma-web-20261030-default.svg` and `figma-web-20261030-ids.svg`
(the date written without dashes), committed raw; see `../README.md`.
1. Select the imported frame, right panel › Export › « + » › SVG.
2. Two exports:
- `…-default.svg`: the defaults;
- `…-ids.svg`: « Include "id" attribute » ticked, « Outline text » unticked
(text kept as text).
## Affinity (Designer 2 or Affinity, if you use it; otherwise say so and A6 drops it)
## Affinity (optional since the owner's decision of 2026-10-30)
File › Open `inkscape-source.svg`, then File › Export › SVG, preset « SVG (for
web) » (`…-web.svg`); if offered, a second with « SVG (digital – high quality) »
@@ -0,0 +1,17 @@
<svg width="180" height="130" viewBox="0 0 180 130" fill="none" xmlns="http://www.w3.org/2000/svg">
<mask id="mask0_3_9" style="mask-type:luminance" maskUnits="userSpaceOnUse" x="0" y="0" width="180" height="130">
<path d="M180 0H0V130H180V0Z" fill="white"/>
</mask>
<g mask="url(#mask0_3_9)">
<path d="M10 100C30 30 140 20 170 90L160 110L20 115L10 100Z" fill="url(#paint0_linear_3_9)"/>
<path d="M11.6667 102.5L10 100C10.2753 99.0363 10.5677 98.0841 10.8767 97.1432M13.3333 105L16.6667 110M18.3333 112.5L20 115L22.9167 114.896M25.8333 114.792L31.6667 114.583M34.5833 114.479L40.4167 114.271M43.3333 114.167L49.1667 113.958M52.0833 113.854L57.9167 113.646M60.8333 113.542L66.6667 113.333M69.5833 113.229L75.4167 113.021M78.3333 112.917L84.1667 112.708M87.0833 112.604L92.9167 112.396M95.8333 112.292L101.667 112.083M104.583 111.979L110.417 111.771M113.333 111.667L119.167 111.458M122.083 111.354L127.917 111.146M130.833 111.042L136.667 110.833M139.583 110.729L145.417 110.521M148.333 110.417L154.167 110.208M157.083 110.104L160 110L161.667 106.667M163.333 103.333L166.667 96.6667M168.333 93.3333L170 90C169.604 89.076 169.194 88.1659 168.771 87.2697M167.46 84.6227C166.537 82.8434 165.56 81.1223 164.53 79.4589M162.926 76.9743C161.811 75.3196 160.643 73.7261 159.425 72.1932M157.527 69.8984C156.227 68.3901 154.878 66.9454 153.482 65.5638M151.337 63.5225C149.871 62.1816 148.359 60.9058 146.805 59.6946M144.431 57.9168C142.821 56.7597 141.172 55.6682 139.486 54.6418M136.924 53.1463C135.196 52.181 133.435 51.281 131.643 50.4458M128.933 49.2409C127.112 48.47 125.264 47.7638 123.392 47.1217M120.571 46.2076C118.681 45.6306 116.77 45.1171 114.843 44.6668M111.942 44.0391C110.004 43.6528 108.052 43.329 106.09 43.0671M103.144 42.7213C101.178 42.5217 99.2039 42.3836 97.2261 42.3064M94.2604 42.2364C92.2833 42.22 90.3048 42.2641 88.3291 42.3682M85.369 42.5693C83.3979 42.7332 81.4317 42.9568 79.4746 43.2396M76.5448 43.7084C74.5956 44.0507 72.6577 44.4521 70.7353 44.9122M67.8622 45.6465C65.9518 46.1663 64.0592 46.7447 62.1887 47.3812M59.3947 48.3815C57.5413 49.0784 55.7122 49.8335 53.9119 50.6464M51.2288 51.9113C49.4519 52.785 47.7061 53.7166 45.9958 54.7056M43.454 56.2342C41.7759 57.2832 40.1357 58.3897 38.5377 59.5531M36.1712 61.3421C34.6161 62.5627 33.1056 63.8399 31.6439 65.1734M29.4896 67.2146C28.0825 68.5995 26.7261 70.04 25.4249 71.5355M23.5252 73.8073C22.2918 75.3427 21.1147 76.9318 19.9981 78.5741M18.3778 81.0635C17.3398 82.7305 16.3625 84.4488 15.4497 86.2179M14.1435 88.8796C13.3152 90.6566 12.5505 92.4819 11.8531 94.3549" stroke-width="2" stroke="#333333"/>
<path d="M150 57C159.941 57 168 51.6274 168 45C168 38.3726 159.941 33 150 33C140.059 33 132 38.3726 132 45C132 51.6274 140.059 57 150 57Z" fill="#C49A6C"/>
<path d="M86 50H54C51.7909 50 50 51.7909 50 54V66C50 68.2091 51.7909 70 54 70H86C88.2091 70 90 68.2091 90 66V54C90 51.7909 88.2091 50 86 50Z" fill="#3366B3" fill-opacity="0.5"/>
</g>
<defs>
<linearGradient id="paint0_linear_3_9" x1="10" y1="42.233" x2="170" y2="42.233" gradientUnits="userSpaceOnUse">
<stop stop-color="#8A5A3C"/>
<stop offset="1" stop-color="#D9B48F" stop-opacity="0.8"/>
</linearGradient>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 3.1 KiB

@@ -0,0 +1,25 @@
<svg width="180" height="130" viewBox="0 0 180 130" fill="none" xmlns="http://www.w3.org/2000/svg">
<g id="Clip path group">
<mask id="mask0_3_9" style="mask-type:luminance" maskUnits="userSpaceOnUse" x="0" y="0" width="180" height="130">
<g id="frame">
<path id="Vector" d="M180 0H0V130H180V0Z" fill="white"/>
</g>
</mask>
<g mask="url(#mask0_3_9)">
<g id="body">
<g id="Vector_2">
<path d="M10 100C30 30 140 20 170 90L160 110L20 115L10 100Z" fill="url(#paint0_linear_3_9)"/>
<path d="M11.6667 102.5L10 100C10.2753 99.0363 10.5677 98.0841 10.8767 97.1432M13.3333 105L16.6667 110M18.3333 112.5L20 115L22.9167 114.896M25.8333 114.792L31.6667 114.583M34.5833 114.479L40.4167 114.271M43.3333 114.167L49.1667 113.958M52.0833 113.854L57.9167 113.646M60.8333 113.542L66.6667 113.333M69.5833 113.229L75.4167 113.021M78.3333 112.917L84.1667 112.708M87.0833 112.604L92.9167 112.396M95.8333 112.292L101.667 112.083M104.583 111.979L110.417 111.771M113.333 111.667L119.167 111.458M122.083 111.354L127.917 111.146M130.833 111.042L136.667 110.833M139.583 110.729L145.417 110.521M148.333 110.417L154.167 110.208M157.083 110.104L160 110L161.667 106.667M163.333 103.333L166.667 96.6667M168.333 93.3333L170 90C169.604 89.076 169.194 88.1659 168.771 87.2697M167.46 84.6227C166.537 82.8434 165.56 81.1223 164.53 79.4589M162.926 76.9743C161.811 75.3196 160.643 73.7261 159.425 72.1932M157.527 69.8984C156.227 68.3901 154.878 66.9454 153.482 65.5638M151.337 63.5225C149.871 62.1816 148.359 60.9058 146.805 59.6946M144.431 57.9168C142.821 56.7597 141.172 55.6682 139.486 54.6418M136.924 53.1463C135.196 52.181 133.435 51.281 131.643 50.4458M128.933 49.2409C127.112 48.47 125.264 47.7638 123.392 47.1217M120.571 46.2076C118.681 45.6306 116.77 45.1171 114.843 44.6668M111.942 44.0391C110.004 43.6528 108.052 43.329 106.09 43.0671M103.144 42.7213C101.178 42.5217 99.2039 42.3836 97.2261 42.3064M94.2604 42.2364C92.2833 42.22 90.3048 42.2641 88.3291 42.3682M85.369 42.5693C83.3979 42.7332 81.4317 42.9568 79.4746 43.2396M76.5448 43.7084C74.5956 44.0507 72.6577 44.4521 70.7353 44.9122M67.8622 45.6465C65.9518 46.1663 64.0592 46.7447 62.1887 47.3812M59.3947 48.3815C57.5413 49.0784 55.7122 49.8335 53.9119 50.6464M51.2288 51.9113C49.4519 52.785 47.7061 53.7166 45.9958 54.7056M43.454 56.2342C41.7759 57.2832 40.1357 58.3897 38.5377 59.5531M36.1712 61.3421C34.6161 62.5627 33.1056 63.8399 31.6439 65.1734M29.4896 67.2146C28.0825 68.5995 26.7261 70.04 25.4249 71.5355M23.5252 73.8073C22.2918 75.3427 21.1147 76.9318 19.9981 78.5741M18.3778 81.0635C17.3398 82.7305 16.3625 84.4488 15.4497 86.2179M14.1435 88.8796C13.3152 90.6566 12.5505 92.4819 11.8531 94.3549" stroke-width="2" stroke="#333333"/>
</g>
<path id="Vector_3" d="M150 57C159.941 57 168 51.6274 168 45C168 38.3726 159.941 33 150 33C140.059 33 132 38.3726 132 45C132 51.6274 140.059 57 150 57Z" fill="#C49A6C"/>
<path id="Vector_4" d="M86 50H54C51.7909 50 50 51.7909 50 54V66C50 68.2091 51.7909 70 54 70H86C88.2091 70 90 68.2091 90 66V54C90 51.7909 88.2091 50 86 50Z" fill="#3366B3" fill-opacity="0.5"/>
</g>
</g>
</g>
<defs>
<linearGradient id="paint0_linear_3_9" x1="10" y1="42.233" x2="170" y2="42.233" gradientUnits="userSpaceOnUse">
<stop stop-color="#8A5A3C"/>
<stop offset="1" stop-color="#D9B48F" stop-opacity="0.8"/>
</linearGradient>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 3.2 KiB

+120
View File
@@ -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)",
"x&#117;rl(#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
+52 -1
View File
@@ -5,12 +5,14 @@
//! reference keeps working; the composition is deterministic.
#![allow(clippy::disallowed_methods, clippy::unwrap_used, clippy::expect_used)]
use std::collections::HashMap;
use std::collections::{HashMap, HashSet};
use faunosteo_core::anatomy::compose::{ComposeError, compose_canvas, compose_highlight};
use faunosteo_core::anatomy::svg::clean::{CleaningOutcome, clean_svg};
use faunosteo_core::anatomy::svg::sanitize::{local_reference_text, url_targets};
use faunosteo_core::anatomy::svg::tree::parse_svg;
use faunosteo_core::anatomy::svg::{Element, SvgRejection, read_svg};
use faunosteo_core::domain::sheet::AnatomicalSheetDocument;
use faunosteo_core::domain::sheet::preview::{
PreviewDrawing, PreviewDrawingStatus, PreviewInput, PreviewSheet, PreviewStatus,
};
@@ -342,3 +344,52 @@ fn every_reference_a_browser_reads_stays_in_its_view() {
assert_eq!(refused["kind"], json!("svg_rejected"), "{value}");
}
}
/// Final review 2026-10-30: a `url(` glued to a longer name (`xurl(#g)`, or after a no-break
/// space) is no reference, and the reader removes it from any attribute, so every drawing the
/// reader keeps composes alike into the canvas, the preview and the PDF view; before, the reader
/// kept it in `class` or `result`, the verdict passed and only the canvas refused.
#[test]
fn the_canvas_the_preview_and_the_pdf_draw_every_drawing_the_reader_keeps() {
let document: AnatomicalSheetDocument = serde_json::from_str(&document()).unwrap();
for (attr, value) in [
("class", "xurl(#g)"),
("class", "-url(#g)"),
("result", "aurl(#g)"),
("values", "_url(#g)"),
("transform", "\u{a0}url(#g)"),
("class", "x&#117;rl(#g)"),
] {
let text = format!(
"{OPEN}<radialGradient id=\"g\"/><g {attr}=\"{value}\"><path fill=\"url(#g)\" \
d=\"M0 0\"/></g></svg>"
);
let read = read_svg(&text).unwrap();
assert_eq!(read.removed, [format!("g@{attr}")], "{value}");
let cleaning = clean_svg(text.as_bytes());
assert_eq!(cleaning.outcome, CleaningOutcome::Cleanable, "{value}");
compose_canvas(&document, "detail", &read.root).unwrap();
compose_highlight(&document, "detail", read.root, &HashSet::new(), false).unwrap();
canvas(&preview(cleaning.stored.as_deref().unwrap()), "detail");
}
}
/// The composer stays fail-closed on a tree that did not come out of the reader: a glued
/// `url(` or a reference leaving the document is never inlined in the page.
#[test]
fn the_composer_refuses_a_reference_it_does_not_scope() {
let document: AnatomicalSheetDocument = serde_json::from_str(&document()).unwrap();
for (attr, value) in [
("class", "xurl(#g)"),
("fill", "url(#%67)"),
("href", "https://example.org/a.svg#g"),
] {
let mut root = read_svg(&detail_drawing()).unwrap().root;
root.set_attr(attr, value.to_owned());
assert_eq!(
compose_canvas(&document, "detail", &root).unwrap_err(),
ComposeError::UnscopedReference,
"{attr}={value}"
);
}
}