fix(anatomy): V1-2.2 owner arbitrations on SVG references and bytes

Refuse local references to ids a drawing does not define, scope canvas
ids per view, upload every drawing in one stored form checked by the
verdict and the preview, keep strict numeric rgb() colours, and commit
real Inkscape 1.4.3 exports with their generator.
This commit is contained in:
bchanot committed 2026-10-29 16:24:07 +01:00
1 parent 17d919971e
commit e823655f09
31 files changed
+1362 -110

No files matched your search

+36
View File
@@ -52,6 +52,15 @@ fn declared(file: &str) -> Option<Value> {
}
// C2: the prescan's per-element attribute cap (TS removes the 3,000 data-like names).
"comment-desync-attributes.svg" => json!({ "rejected": "too_complex" }),
// V1-2.2 owner decision 2026-10-29: a reference to an id the drawing does not define
// is refused (TS dropped nothing; inlined, it would resolve against the page).
"dangling-references.svg" => json!({ "rejected": "dangling_reference" }),
// V1-2.2 owner decision 2026-10-29: a strict numeric `rgb()` colour is kept (TS removed
// any function); the five other styles stay removed.
"css.svg" => {
json!({ "removed": ["path@style", "path@style", "path@style", "path@style", "path@style"],
"rust_keeps": [["path", "style", "fill:rgb(1,2,3)"]] })
}
// C3 root: no class or style on the inline root.
"root-class-style.svg" => json!({ "removed": ["svg@class", "svg@style"] }),
_ => return None,
@@ -82,6 +91,25 @@ fn strip(tree: &mut Value, element: &str, attribute: &str) {
}
}
/// Removes the attribute holding exactly `value` from elements of that local name (a value
/// the Rust reader keeps on purpose); whether one was found.
fn strip_value(tree: &mut Value, element: &str, attribute: &str, value: &str) -> bool {
let mut found = false;
if tree["name"] == element
&& let Some(attrs) = tree["attrs"].as_object_mut()
&& attrs.get(attribute).and_then(Value::as_str) == Some(value)
{
attrs.remove(attribute);
found = true;
}
if let Some(children) = tree["children"].as_array_mut() {
for child in children {
found |= strip_value(child, element, attribute, value);
}
}
found
}
/// Removes `href`/`xlink:href` values that start with a non-ASCII character (a declared removal).
fn strip_unicode_spaced_refs(tree: &mut Value) {
if let Some(attrs) = tree["attrs"].as_object_mut() {
@@ -158,6 +186,14 @@ fn every_hostile_case_gives_the_typescript_verdict_or_a_declared_one() {
}
Some(expected) => {
assert_eq!(rust["removed"], expected["removed"], "{file}");
let mut rust = rust.clone();
for kept in expected["rust_keeps"].as_array().into_iter().flatten() {
let [element, attribute, value] = [0, 1, 2].map(|i| kept[i].as_str().unwrap());
assert!(
strip_value(&mut rust["tree"], element, attribute, value),
"{file}"
);
}
let mut tree = declared_tree(&ts["tree"], false, true).unwrap();
if expected["strip_unicode_spaced_refs"] == true {
strip_unicode_spaced_refs(&mut tree);