Skip to content

Commit 9214967

Browse files
committed
consume unsupported elements
1 parent dff2106 commit 9214967

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed
Lines changed: 10 additions & 0 deletions
Loading

golden/simple/mask_with_use.png

633 Bytes
Loading

lib/src/svg/parser_state.dart

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,27 @@ class SvgParserState {
607607
/// The current depth of the reader in the XML hierarchy.
608608
int depth = 0;
609609

610+
void _discardSubtree() {
611+
final int subtreeStartDepth = depth;
612+
while (_eventIterator.moveNext()) {
613+
final XmlEvent event = _eventIterator.current;
614+
if (event == null) {
615+
return;
616+
}
617+
if (event is XmlStartElementEvent && !event.isSelfClosing) {
618+
depth += 1;
619+
} else if (event is XmlEndElementEvent) {
620+
depth -= 1;
621+
assert(depth >= 0);
622+
}
623+
_currentAttributes = <XmlElementAttribute>[];
624+
_currentStartElement = null;
625+
if (depth < subtreeStartDepth) {
626+
return;
627+
}
628+
}
629+
}
630+
610631
Iterable<XmlEvent> _readSubtree() sync* {
611632
final int subtreeStartDepth = depth;
612633
while (_eventIterator.moveNext()) {
@@ -644,12 +665,15 @@ class SvgParserState {
644665
}
645666
final _ParseFunc parseFunc = _svgElementParsers[event.name];
646667
await parseFunc?.call(this);
647-
assert(() {
648-
if (parseFunc == null) {
649-
unhandledElement(event);
668+
if (parseFunc == null) {
669+
if (!event.isSelfClosing) {
670+
_discardSubtree();
650671
}
651-
return true;
652-
}());
672+
assert(() {
673+
unhandledElement(event);
674+
return true;
675+
}());
676+
}
653677
} else if (event is XmlEndElementEvent) {
654678
endElement(event);
655679
}

0 commit comments

Comments
 (0)