From 7d9ab8cf2f77e4d28abd7eabe8e655aa4fcd448a Mon Sep 17 00:00:00 2001 From: bchanot Date: Fri, 30 Oct 2026 15:05:56 +0100 Subject: [PATCH] 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. --- crates/core/src/anatomy/compose.rs | 6 +- crates/core/src/anatomy/svg/sanitize.rs | 18 ++- .../core/tests/fixtures/svg/exports/README.md | 22 +++- .../fixtures/svg/exports/owner/README.md | 8 +- .../owner/figma-web-20261030-default.svg | 17 +++ .../exports/owner/figma-web-20261030-ids.svg | 25 ++++ crates/core/tests/svg_clean.rs | 120 ++++++++++++++++++ crates/core/tests/svg_scope.rs | 53 +++++++- docs/ANNOTATION-RENDERING.md | 4 +- docs/development/RUST.md | 28 +++- docs/development/V1-2_ANATOMICAL_SHEETS.md | 11 ++ 11 files changed, 299 insertions(+), 13 deletions(-) create mode 100644 crates/core/tests/fixtures/svg/exports/owner/figma-web-20261030-default.svg create mode 100644 crates/core/tests/fixtures/svg/exports/owner/figma-web-20261030-ids.svg diff --git a/crates/core/src/anatomy/compose.rs b/crates/core/src/anatomy/compose.rs index 039ace61..e00df75a 100644 --- a/crates/core/src/anatomy/compose.rs +++ b/crates/core/src/anatomy/compose.rs @@ -31,8 +31,10 @@ pub enum ComposeError { UnknownView, /// A label or a path of the layer holds a code point XML 1.0 cannot carry. InvalidCharacter, - /// A reference of the drawing kept outside its view's scope after scoping (fail-closed: - /// the reader keeps no such reference, so this never happens on a read drawing). + /// A reference of the drawing kept outside its view's scope after scoping, or a `url(` the + /// scoping does not read. Fail-closed: the reader keeps no attribute with a `url(` it does + /// not read as a local reference (`sanitize::value_acceptable`), so only an element tree + /// that did not come out of `read_svg` reaches it. UnscopedReference, } diff --git a/crates/core/src/anatomy/svg/sanitize.rs b/crates/core/src/anatomy/svg/sanitize.rs index ff4903cb..085659b2 100644 --- a/crates/core/src/anatomy/svg/sanitize.rs +++ b/crates/core/src/anatomy/svg/sanitize.rs @@ -44,7 +44,7 @@ const ALLOWED_ELEMENTS: [&str; 28] = [ "use", ]; -const ALLOWED_ATTRIBUTES: [&str; 74] = [ +const ALLOWED_ATTRIBUTES: [&str; 77] = [ "id", "class", "d", @@ -110,6 +110,9 @@ const ALLOWED_ATTRIBUTES: [&str; 74] = [ "color-interpolation-filters", "filterUnits", "primitiveUnits", + "maskUnits", + "maskContentUnits", + "clipPathUnits", "systemLanguage", "font-family", "font-size", @@ -415,12 +418,16 @@ fn is_xml_space(text: &str) -> bool { /// The engine's value rules, in its order, then the R3 id grammar. fn value_acceptable(qname: &str, value: &str) -> bool { - if value.contains('\\') || !urls_are_local(value) { + if value.contains('\\') || !urls_are_local(value) || !urls_unglued(value) { return false; } match qname { "href" | "xlink:href" => is_local_reference(local_reference_text(value)), "id" => is_reference_name(value), + // Figma writes `maskUnits="userSpaceOnUse"` (owner decision 2026-10-30): the keywords only. + "maskUnits" | "maskContentUnits" | "clipPathUnits" => { + matches!(value, "userSpaceOnUse" | "objectBoundingBox") + } "style" => !style_forbidden(value) && calls_only_local_url(value), _ if PRESENTATION_ATTRIBUTES.contains(&qname) => calls_only_local_url(value), _ => true, @@ -542,6 +549,13 @@ pub fn urls_are_local(value: &str) -> bool { url_openings(value).all(|at| local_url_target(value, at).is_some()) } +/// Every case-insensitive `url(` of the value is one `url_openings` reads: no attribute keeps a +/// `url(` glued to a longer name (`xurl(#a)`, final review 2026-10-30), so a kept value holds +/// as many `url(` as references, the count the composer checks. +fn urls_unglued(value: &str) -> bool { + value.to_ascii_lowercase().matches("url(").count() == url_openings(value).count() +} + /// No `(` once the `url(#` openings and the strict colour functions are taken out. fn calls_only_local_url(value: &str) -> bool { let mut cut = String::with_capacity(value.len()); diff --git a/crates/core/tests/fixtures/svg/exports/README.md b/crates/core/tests/fixtures/svg/exports/README.md index 3229b83d..46c8802c 100644 --- a/crates/core/tests/fixtures/svg/exports/README.md +++ b/crates/core/tests/fixtures/svg/exports/README.md @@ -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 `---.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 +`` 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). diff --git a/crates/core/tests/fixtures/svg/exports/owner/README.md b/crates/core/tests/fixtures/svg/exports/owner/README.md index e327e723..c5d493cd 100644 --- a/crates/core/tests/fixtures/svg/exports/owner/README.md +++ b/crates/core/tests/fixtures/svg/exports/owner/README.md @@ -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) » diff --git a/crates/core/tests/fixtures/svg/exports/owner/figma-web-20261030-default.svg b/crates/core/tests/fixtures/svg/exports/owner/figma-web-20261030-default.svg new file mode 100644 index 00000000..d96d012a --- /dev/null +++ b/crates/core/tests/fixtures/svg/exports/owner/figma-web-20261030-default.svg @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/crates/core/tests/fixtures/svg/exports/owner/figma-web-20261030-ids.svg b/crates/core/tests/fixtures/svg/exports/owner/figma-web-20261030-ids.svg new file mode 100644 index 00000000..fb671fa0 --- /dev/null +++ b/crates/core/tests/fixtures/svg/exports/owner/figma-web-20261030-ids.svg @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/crates/core/tests/svg_clean.rs b/crates/core/tests/svg_clean.rs index 80cb225b..4ece1ea2 100644 --- a/crates/core/tests/svg_clean.rs +++ b/crates/core/tests/svg_clean.rs @@ -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!( + "\ + " + ) + }; + 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!( + "" + ); + assert_eq!( + outcome(&clean_svg(svg.as_bytes())), + (Clean, None), + "{attr}={value}" + ); + } + for value in ["", " userSpaceOnUse", "userspaceonuse", "url(#m)", "x(1)"] { + let svg = format!( + "" + ); + 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("" + ); + 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}" + ); + } +} diff --git a/docs/ANNOTATION-RENDERING.md b/docs/ANNOTATION-RENDERING.md index 8997d04f..8ae2f587 100644 --- a/docs/ANNOTATION-RENDERING.md +++ b/docs/ANNOTATION-RENDERING.md @@ -83,7 +83,9 @@ keep a reference outside its scope. A drawing whose reference names an id it does not define is refused by the reader (`dangling_reference`); a `url(` spelt any other way than `url(#id)` with optional quotes and spaces is removed by the reader, so the cleaning refuses the file as active content and the verdict as a -removal. The annotation +removal. A `url(` glued to a longer name (`xurl(#a)`) is no reference: the reader +removes the attribute holding it, whatever the attribute (2026-10-30), so every +drawing the reader keeps composes into the canvas and the PDF view alike. The annotation layer carries no `id`. The PDF view keeps the drawing's ids: it is rasterised as a document of its own. The R3 canvas goldens stay frozen; the tests apply this declared change to them (`withIdsScopedPerView`, diff --git a/docs/development/RUST.md b/docs/development/RUST.md index 0f3cfac8..19e8e0af 100644 --- a/docs/development/RUST.md +++ b/docs/development/RUST.md @@ -3950,7 +3950,7 @@ trapping test stub (`apps/app/tests/helpers/core.ts`) lists the two new glue mem | Measure | Value | |---|---| -| shipped module | 1 512 413 B raw, 558 859 B gzip -9 (script), 568 696 B by Node's gzip in `size.test.ts` (final, f1ef6a4: the debug `name` section dropped, §12.7); budget 600 000 (D-R13); 596 671 B at ca31b78, 531 715 B before V1-2.2 (RUST.md §11.22) | +| shipped module | 1 513 522 B raw, 559 360 B gzip -9 (script), 569 181 B by Node's gzip in `size.test.ts` (final, finalisation §12.8; 568 696 B at f1ef6a4, the debug `name` section dropped since §12.7); budget 600 000 (D-R13); 596 671 B at ca31b78, 531 715 B before V1-2.2 (RUST.md §11.22) | | verdict at every cap, native | 107 ms release, 493 ms debug (document 1 165 850 bytes) | | `clean_svg`, shipped module | 45 hostile inputs and floods, slowest 0.4 ms | @@ -3969,11 +3969,12 @@ with a PI shown `rejected` by the preview as the verdict refuses it. ### 12.6 Residual risks and points for V1-2.3 -- The module's margin under its budget is about 31.3 KB by the test's measure since §12.7 (3.3 KB before): the V1-2.5 and V1-2.6 pages must not grow the +- The module's margin under its budget is about 30.8 KB by the test's measure since §12.8 (31.3 KB at §12.7) (3.3 KB before): the V1-2.5 and V1-2.6 pages must not grow the core's browser surface without measuring. - cairo colours: closed at the checkpoint (§12.7), strict numeric `rgb()` / `rgba()` kept. -- Editor exports: Inkscape 1.4.3 covered at the checkpoint (§12.7); Illustrator, Figma and Affinity pending from the - owner, their real output untested until then (A6 open). +- Editor exports: Inkscape 1.4.3 covered at the checkpoint (§12.7), Figma at the finalisation (§12.8); the real Adobe + Illustrator pending from the owner, its output untested until then (A6 open); Affinity optional. Figma's text + handling is untested: neither owner file carries the source's live text. - A verdict whose document does not read strictly carries no group and no drawing: M6's structure check (`complete_sheet_verification`) must accept a failed verdict without them, or the round would wait for its attempt limit. - `PreviewSheet` handles are not yet under `CoreRuntime`'s poison and recovery (§8.3): the first page that holds one adds @@ -4049,3 +4050,22 @@ gzip, but `is_url` must keep matching `new URL()`), the PDF writer, reader and i (about 55 to 60 KB gzip by the attribution above, estimated; the editor pages never export), `wasm-opt -Oz` in the build (not installed here; to be measured). No security check, validation or feature is removed for size. + +### 12.8 Finalisation (owner, 2026-10-30) + +Brief « V1-2.2 : finalisation et intégration A6 Figma » on `98060d7`, after the final independent review of `05de816` +(verifier ECARTS(3): A6 open, a LOW in `f1ef6a4`, a floor false positive; security PASS). Decisions in contract §17.5. + +| Point | Built | Where | +|---|---|---| +| Glued `url(` | `sanitize::urls_unglued`: a value keeps every case-insensitive `url(` only when `url_openings` reads each one, so no attribute keeps `xurl(#a)` (or `url(` after a no-break space); before, `class`, `result`, `values` kept it, the verdict passed and only the canvas refused it (`unscoped_reference`) while the PDF drew it. Same helper as the reader, no second parser; the composer's count now holds on every read drawing | `anatomy/svg/sanitize.rs`, `anatomy/compose.rs` (comment) | +| Mask and clip units | `maskUnits`, `maskContentUnits`, `clipPathUnits` allowed, values `userSpaceOnUse` / `objectBoundingBox` only | `anatomy/svg/sanitize.rs` | +| Figma | the owner's two raw exports committed under `fixtures/svg/exports/owner/`: `default` clean, `ids` cleanable (`g@id`); stored forms pixel-identical to the raw files in Chromium 156 (208 pixels at × 8 differed before the units were allowed) | `tests/svg_clean.rs`, exports README | + +Tests: `svg_clean` (`every_attribute_reads_url_with_the_one_grammar`: six attributes × nine glued spellings removed, +five non-strict or escaped spellings refused, an absent target refused, six values kept; +`mask_and_clip_units_keep_their_keywords_only`; `the_figma_exports_keep_their_mask_gradient_and_shapes`); `svg_scope` +(`the_canvas_the_preview_and_the_pdf_draw_every_drawing_the_reader_keeps`, `the_composer_refuses_a_reference_it_does_not_scope`, +which reaches the fail-closed branch on a tree built outside the reader). Mutations: dropping `urls_unglued`, the +keyword check or the `maskUnits` entry each fails the new tests. No frozen oracle, N-1 copy, protected reader or equine +file changed. diff --git a/docs/development/V1-2_ANATOMICAL_SHEETS.md b/docs/development/V1-2_ANATOMICAL_SHEETS.md index 4fd22c6b..d93a578a 100644 --- a/docs/development/V1-2_ANATOMICAL_SHEETS.md +++ b/docs/development/V1-2_ANATOMICAL_SHEETS.md @@ -2385,6 +2385,17 @@ Asked before the code of V1-2.2, on the brief « Autorisation de démarrer V1-2. | Inkscape exports | the Ubuntu archive package of Inkscape 1.4.3 unpacked in the session scratch folder (no install) produces real exports, committed with their generator; Illustrator and Figma stay owner-supplied, A6 open until they arrive | §9.2, §15 | | Module size | the shipped module drops wasm-bindgen's debug `name` section (`--remove-name-section`); the 600 000-byte cap and its test are kept | RUST.md §12 | +### 17.5 V1-2.2 finalisation (owner, 2026-10-30) + +Brief « V1-2.2 : finalisation et intégration A6 Figma », after the final independent review of `05de816`: + +| Item | Decision | Where | +|---|---|---| +| Editor exports required for A6 | Inkscape (covered, §17.4), Figma (required: the owner's two raw exports `owner/figma-web-20261030-{default,ids}.svg`) and Illustrator (required: the real Adobe Illustrator; VectorCraft or any look-alike is not equivalent). Affinity is optional. A6 stays open until the Illustrator exports are committed and pass | §9.2, §15 | +| Mask and clip units | `maskUnits`, `maskContentUnits` and `clipPathUnits` kept with the keywords `userSpaceOnUse` and `objectBoundingBox` only, any other value removed: removing Figma's `maskUnits="userSpaceOnUse"` re-read the mask region in bounding-box units and cut the drawing's edge | §9.2 | +| Glued `url(` | a `url(` glued to a longer name (`xurl(#a)`) is removed from any attribute, not only from presentation attributes and `style`, so the reader, the cleaning, the verdict, the preview, the canvas and the PDF view accept the same drawings | §9.2, §10 | +| Document instances | the per-document prefix (§10) stays a requirement before any page draws two documents at once | §10 | + --- ## 18. Documents touched by V1-2.0