Merge pull request #2410 from storytold/refactor/svg-shared-xml-escaping

SVG: reuse shared XML escaping and character validation
This commit is contained in:
FredApps authored and GitHub committed 2026-11-16 17:21:17 +01:00
commit 4548d6c009
6 files changed
+29 -10

No files matched your search

Generated
+10
View File
@@ -1236,6 +1236,15 @@ dependencies = [
"wayland-client",
]
[[package]]
name = "craft-xml"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=d13ac58a15c45d618f25910772502e38c4ce1d4c#d13ac58a15c45d618f25910772502e38c4ce1d4c"
dependencies = [
"quick-xml 0.41.0",
"thiserror 2.0.21",
]
[[package]]
name = "craft-zip"
version = "0.1.0"
@@ -2141,6 +2150,7 @@ name = "figcraft-svg"
version = "0.18.1"
dependencies = [
"base64 0.22.1",
"craft-xml",
"figcraft-color",
"figcraft-doc",
"figcraft-geom",
+1
View File
@@ -13,6 +13,7 @@ rust-version = "1.95"
repository = "https://github.com/storytold/figcraft"
[workspace.dependencies]
craft-xml = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "d13ac58a15c45d618f25910772502e38c4ce1d4c" }
craft-vectordrawable = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "d13ac58a15c45d618f25910772502e38c4ce1d4c" }
# internal
figcraft-geom = { path = "crates/geom" }
+1
View File
@@ -9,6 +9,7 @@ description = "FigCraft SVG export (shapes, gradients, images, strokes, effects
workspace = true
[dependencies]
craft-xml = { workspace = true }
figcraft-geom = { workspace = true }
figcraft-color = { workspace = true }
figcraft-doc = { workspace = true }
+3 -10
View File
@@ -195,16 +195,9 @@ fn blend_style(b: figcraft_color::BlendMode) -> String {
}
}
/// `s` escaped for XML text and attribute values; characters XML 1.0 forbids (control characters
/// other than tab, newline and carriage return, U+FFFE and U+FFFF) are left out.
fn esc(s: &str) -> String {
s.chars().filter(|&c| xml_char(c)).collect::<String>().replace('&', "&amp;").replace('<', "&lt;").replace('>', "&gt;").replace('"', "&quot;")
}
/// Whether XML 1.0 allows `c` (see [`esc`]).
fn xml_char(c: char) -> bool {
!matches!(c, '\u{0}'..='\u{8}' | '\u{b}' | '\u{c}' | '\u{e}'..='\u{1f}' | '\u{fffe}' | '\u{ffff}')
}
// Shared XML wire escaping and character validity; layer-name policy stays below.
// Attribute escaping also preserves tabs/LF/CR through XML readers' whitespace normalization.
use craft_xml::{esc_attr as esc, is_xml_char as xml_char};
fn hex(c: Color) -> String {
format!("#{}", c.to_hex())
+12
View File
@@ -451,3 +451,15 @@ fn a_whole_ellipse_drawn_backwards_keeps_its_simple_stroke() {
assert_eq!(backwards, forwards, "{align:?}");
}
}
#[test]
fn shared_xml_escaping_keeps_markup_controls_and_attribute_whitespace() {
let input = "A<&\"'\t\n\r\u{1}\u{fffe}🦊";
assert_eq!(super::esc(input), "A&lt;&amp;&quot;'&#9;&#10;&#13;🦊");
let markup = format!("<svg label=\"{}\"/>", super::esc(input));
let root = craft_xml::parse(markup.as_bytes()).unwrap();
assert_eq!(root.attr("label"), Some("A<&\"'\t\n\r🦊"));
for c in ['\0', '\u{b}', '\u{fffe}', '\u{ffff}'] {
assert!(!super::xml_char(c));
}
}
+2
View File
@@ -11,6 +11,8 @@ summarizes it; [`gaps.md`](gaps.md) is the ranked work list; the measured menu c
[`prototyping-parity.md`](prototyping-parity.md), [`dev-mode-parity.md`](dev-mode-parity.md),
[`collaboration-parity.md`](collaboration-parity.md), [`boards-parity.md`](boards-parity.md).
> SVG XML wire follow-up (2026-11-16): export escaping and XML 1.0 character checks delegate to pinned `craft-xml`. Attribute tab/LF/CR are emitted as references to survive XML normalization. Local SVG document/path serialization and import mapping remain; this scoped change does not raise the parity grade. Hosted validation is pending.
## Headline
| Number | Value | Kind |