File tree Expand file tree Collapse file tree 3 files changed +39
-5
lines changed
Expand file tree Collapse file tree 3 files changed +39
-5
lines changed Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments