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

+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", "xurl(#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}"
);
}
}