fix(anatomy): V1-2.2 refuse a root visibility that hides the markers
Both composers append the marker layer as the root's last child, so a root visibility="hidden" whose children set visible back drew the drawing without a marker (0 marker pixels in Chromium and Firefox, PDF and canvas). The reader refuses any root visibility but visible (root_visibility); cleaning, verdict, preview, PDF gate and both composers answer it.
This commit is contained in:
1 parent
81f7639c75
commit
d8562f60f5
14 files changed
+509
-169
No files matched your search
@@ -0,0 +1,240 @@
|
||||
//! V1-2.2 owner brief 2026-10-30: the drawing's root never decides whether the engine's markers
|
||||
//! show. Both composers append the marker layer as the root's last child (the PDF view keeps the
|
||||
//! drawing's root, the canvas copies its attributes), so the layer inherits the root's
|
||||
//! `visibility`; a drawing `<svg visibility="hidden">` whose children set `visible` back read
|
||||
//! clean before and showed its drawing without a single marker (security review, MEDIUM). The
|
||||
//! reader refuses a root `visibility` other than `visible` (`root_visibility`); the cleaning,
|
||||
//! the preview, the verdict and the PDF snapshot gate answer it; both composers refuse such a
|
||||
//! root. The other root properties are either removed by the reader already or affect the
|
||||
//! drawing and the markers alike (see `other_root_properties_*`).
|
||||
#![allow(clippy::disallowed_methods, clippy::unwrap_used, clippy::expect_used)]
|
||||
|
||||
mod common;
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
use common::sheet_readers::{
|
||||
OPEN, assert_refused_everywhere, canvas_outcome, preview, sheet, verdict_detail,
|
||||
};
|
||||
use faunosteo_core::anatomy::compose::{ComposeError, compose_canvas, compose_highlight};
|
||||
use faunosteo_core::anatomy::svg::clean::{CleaningOutcome, clean_svg};
|
||||
use faunosteo_core::anatomy::svg::tree::parse_svg;
|
||||
use faunosteo_core::anatomy::svg::{Element, read_svg};
|
||||
use faunosteo_core::domain::sheet::verdict::DrawingResult;
|
||||
use serde_json::json;
|
||||
|
||||
const BODY: &str = "<g visibility=\"visible\"><path d=\"M0 0h10v10z\"/></g>";
|
||||
|
||||
/// A drawing whose root opening tag carries `attrs`.
|
||||
fn rooted(attrs: &str, body: &str) -> String {
|
||||
let root = OPEN.replace("viewBox", &format!("{attrs} viewBox"));
|
||||
format!("{root}{body}</svg>")
|
||||
}
|
||||
|
||||
/// The composed view's marker layer is its root's last child and the root lets it show.
|
||||
fn layer_shows(composed: &Element) -> bool {
|
||||
let layer = composed.element_children().last().unwrap();
|
||||
let root_visible = composed
|
||||
.attr("visibility")
|
||||
.is_none_or(|v| v.trim().eq_ignore_ascii_case("visible"));
|
||||
layer.element_children().count() > 0 && root_visible
|
||||
}
|
||||
|
||||
fn compose_both(tree: &Element) -> (Result<Element, ComposeError>, Result<Element, ComposeError>) {
|
||||
let sheet = sheet();
|
||||
let ids: HashSet<&str> = ["hock"].into_iter().collect();
|
||||
(
|
||||
compose_canvas(&sheet, "main", tree),
|
||||
compose_highlight(&sheet, "main", tree.clone(), &ids, true),
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_drawing_without_root_visibility_shows_its_markers() {
|
||||
for root in [
|
||||
"",
|
||||
"visibility=\"visible\"",
|
||||
"visibility=\"Visible\"",
|
||||
"visibility=\" visible\t\"",
|
||||
] {
|
||||
let text = rooted(root, BODY);
|
||||
let read = read_svg(&text).unwrap_or_else(|e| panic!("{root}: {e:?}"));
|
||||
assert!(read.removed.is_empty(), "{root}");
|
||||
let cleaning = clean_svg(text.as_bytes());
|
||||
assert_eq!(cleaning.outcome, CleaningOutcome::Clean, "{root}");
|
||||
// The verdict and the preview read the stored form, as uploaded.
|
||||
let stored = cleaning.stored.unwrap();
|
||||
assert_eq!(
|
||||
verdict_detail(&stored),
|
||||
(false, DrawingResult::Ok, None),
|
||||
"{root}"
|
||||
);
|
||||
assert_eq!(
|
||||
canvas_outcome(&preview(&stored), "detail")["ok"],
|
||||
json!(true),
|
||||
"{root}"
|
||||
);
|
||||
let (canvas, highlight) = compose_both(&read.root);
|
||||
assert!(layer_shows(&canvas.unwrap()), "{root}");
|
||||
assert!(layer_shows(&highlight.unwrap()), "{root}");
|
||||
}
|
||||
}
|
||||
|
||||
/// The reported drawing and every spelling of a non-visible root: refused by every reader.
|
||||
#[test]
|
||||
fn a_root_visibility_other_than_visible_is_refused_everywhere() {
|
||||
let values = [
|
||||
"hidden",
|
||||
"collapse",
|
||||
"HIDDEN",
|
||||
"Hidden",
|
||||
" hidden ",
|
||||
"hidden\n",
|
||||
"hidden",
|
||||
"hidden",
|
||||
"inherit",
|
||||
"initial",
|
||||
"unset",
|
||||
"revert",
|
||||
"hidden !important",
|
||||
"visible hidden",
|
||||
"visibl",
|
||||
"",
|
||||
];
|
||||
let bodies = [
|
||||
BODY,
|
||||
"<g style=\"visibility:visible\"><path d=\"M0 0h10v10z\"/></g>",
|
||||
"<path visibility=\"visible\" d=\"M0 0h10v10z\"/>",
|
||||
"<path d=\"M0 0h10v10z\"/>",
|
||||
];
|
||||
for value in values {
|
||||
for body in bodies {
|
||||
assert_refused_everywhere(
|
||||
&rooted(&format!("visibility=\"{value}\""), body),
|
||||
"root_visibility",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The composers stay fail-closed on a root that did not come out of the reader.
|
||||
#[test]
|
||||
fn the_composers_never_give_the_layer_a_hidden_root() {
|
||||
for value in ["hidden", "collapse", "HIDDEN", "inherit"] {
|
||||
let tree = parse_svg(&rooted(&format!("visibility=\"{value}\""), BODY)).unwrap();
|
||||
let (canvas, highlight) = compose_both(&tree);
|
||||
assert_eq!(canvas.unwrap_err(), ComposeError::RootVisibility, "{value}");
|
||||
assert_eq!(
|
||||
highlight.unwrap_err(),
|
||||
ComposeError::RootVisibility,
|
||||
"{value}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The same property written another way never reaches the root: a root `style` or `class`
|
||||
/// and a `<style>` element are removed (the cleaning offers the drawing without them, and its
|
||||
/// stored form reads back clean), and a descendant's `visibility` stays in the drawing, never
|
||||
/// on the layer's ancestors.
|
||||
#[test]
|
||||
fn equivalent_styles_never_hide_the_layer() {
|
||||
let cleanable = [
|
||||
(rooted("style=\"visibility:hidden\"", BODY), "svg@style"),
|
||||
(rooted("style=\"VISIBILITY: hidden\"", BODY), "svg@style"),
|
||||
(rooted("class=\"invisible\"", BODY), "svg@class"),
|
||||
(
|
||||
rooted(
|
||||
"",
|
||||
&format!("<style>svg{{visibility:hidden}}</style>{BODY}"),
|
||||
),
|
||||
"style",
|
||||
),
|
||||
(
|
||||
rooted(
|
||||
"",
|
||||
&format!("<style>:root{{visibility:collapse}}</style>{BODY}"),
|
||||
),
|
||||
"style",
|
||||
),
|
||||
];
|
||||
for (text, removal) in &cleanable {
|
||||
let read = read_svg(text).unwrap();
|
||||
assert!(
|
||||
read.removed.iter().any(|r| r == removal),
|
||||
"{text}: {:?}",
|
||||
read.removed
|
||||
);
|
||||
let cleaning = clean_svg(text.as_bytes());
|
||||
assert_eq!(cleaning.outcome, CleaningOutcome::Cleanable, "{text}");
|
||||
let stored = cleaning.stored.unwrap();
|
||||
let again = clean_svg(stored.as_bytes());
|
||||
assert_eq!(
|
||||
(again.outcome, again.stored.as_deref()),
|
||||
(CleaningOutcome::Clean, Some(stored.as_str())),
|
||||
"the stored form is a fixpoint: {text}"
|
||||
);
|
||||
let (canvas, highlight) = compose_both(&read_svg(&stored).unwrap().root);
|
||||
assert!(
|
||||
layer_shows(&canvas.unwrap()) && layer_shows(&highlight.unwrap()),
|
||||
"{text}"
|
||||
);
|
||||
}
|
||||
let descendant = rooted(
|
||||
"",
|
||||
"<g visibility=\"hidden\"><path d=\"M0 0h10v10z\"/></g><path style=\"visibility:collapse\" d=\"M0 0h1\"/>",
|
||||
);
|
||||
let read = read_svg(&descendant).unwrap();
|
||||
assert!(read.removed.is_empty());
|
||||
let (canvas, highlight) = compose_both(&read.root);
|
||||
assert!(layer_shows(&canvas.unwrap()) && layer_shows(&highlight.unwrap()));
|
||||
}
|
||||
|
||||
/// The other root properties that reach the layer. Removed by the reader before V1-2.2: the
|
||||
/// paint servers and effects (`filter`, `mask`, `clip-path`), `transform`, `class`, `style`.
|
||||
/// Kept: `opacity` and `display` act on the whole root, drawing and markers alike (the
|
||||
/// browser proofs of RUST.md §12.10 show both); `fill` and `fill-opacity` are set on every PDF
|
||||
/// marker. The stroke properties no marker sets (`stroke-opacity`, `stroke-dasharray`,
|
||||
/// `stroke-width` on the hitbox) are an open owner decision, not covered here.
|
||||
#[test]
|
||||
fn other_root_properties_are_removed_or_act_on_the_whole_view() {
|
||||
for name in ["filter", "mask", "clip-path"] {
|
||||
let text = rooted(
|
||||
&format!("{name}=\"url(#m)\""),
|
||||
&format!("<mask id=\"m\"/>{BODY}"),
|
||||
);
|
||||
let read = read_svg(&text).unwrap();
|
||||
assert!(read.removed.contains(&format!("svg@{name}")), "{name}");
|
||||
assert!(read.root.attr(name).is_none(), "{name}");
|
||||
}
|
||||
let read = read_svg(&rooted("transform=\"scale(0)\"", BODY)).unwrap();
|
||||
assert_eq!(read.removed, ["svg@transform"]);
|
||||
|
||||
for root in [
|
||||
"opacity=\"0\"",
|
||||
"display=\"none\"",
|
||||
"fill=\"none\"",
|
||||
"fill-opacity=\"0\"",
|
||||
] {
|
||||
let read = read_svg(&rooted(root, BODY)).unwrap_or_else(|e| panic!("{root}: {e:?}"));
|
||||
assert!(read.removed.is_empty(), "{root}");
|
||||
let ids: HashSet<&str> = ["hock"].into_iter().collect();
|
||||
let composed = compose_highlight(&sheet(), "main", read.root, &ids, true).unwrap();
|
||||
for marker in composed
|
||||
.element_children()
|
||||
.last()
|
||||
.unwrap()
|
||||
.element_children()
|
||||
{
|
||||
assert!(marker.attr("fill").is_some() && marker.attr("fill-opacity").is_some());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_equine_drawing_has_no_root_visibility() {
|
||||
let horse = common::repo_file("supabase/seed/anatomical-sheets/equine/draft/assets/horse.svg");
|
||||
let read = read_svg(&horse).unwrap();
|
||||
assert!(read.root.attr("visibility").is_none() && read.removed.is_empty());
|
||||
let (canvas, highlight) = compose_both(&read.root);
|
||||
assert!(canvas.is_ok() && highlight.is_ok());
|
||||
}
|
||||
Reference in new issue
Block a user