Skip to content

Commit 6debc44

Browse files
authored
Support SVGs without the xmlns attribute on the root (#892)
1 parent 7b5464a commit 6debc44

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

crates/usvg/src/parser/svgtree/parse.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ pub(crate) fn parse_tag_name(node: roxmltree::Node) -> Option<EId> {
136136
return None;
137137
}
138138

139-
if node.tag_name().namespace() != Some(SVG_NS) {
139+
if !matches!(node.tag_name().namespace(), None | Some(SVG_NS)) {
140140
return None;
141141
}
142142

crates/usvg/tests/parser.rs

+12
Original file line numberDiff line numberDiff line change
@@ -490,3 +490,15 @@ fn path_transform_in_svg() {
490490
usvg::Transform::from_translate(100.0, 150.0)
491491
);
492492
}
493+
494+
#[test]
495+
fn svg_without_xmlns() {
496+
let svg = "
497+
<svg viewBox='0 0 100 100'>
498+
<rect x='0' y='0' width='10' height='10'/>
499+
</svg>
500+
";
501+
502+
let tree = usvg::Tree::from_str(&svg, &usvg::Options::default()).unwrap();
503+
assert_eq!(tree.size(), usvg::Size::from_wh(100.0, 100.0).unwrap());
504+
}

0 commit comments

Comments
 (0)