diff --git a/src/display/xml_parser.js b/src/display/xml_parser.js index 03f64cd3d..38de48cbe 100644 --- a/src/display/xml_parser.js +++ b/src/display/xml_parser.js @@ -287,6 +287,9 @@ class SimpleDOMNode { return undefined; } const index = childNodes.indexOf(this); + if (index === -1) { + return undefined; + } return childNodes[index + 1]; } @@ -364,8 +367,11 @@ class SimpleXMLParser extends XMLParserBase { } onEndElement(name) { - this._currentFragment = this._stack.pop(); + this._currentFragment = this._stack.pop() || []; const lastElement = this._currentFragment[this._currentFragment.length - 1]; + if (!lastElement) { + return; + } for (let i = 0, ii = lastElement.childNodes.length; i < ii; i++) { lastElement.childNodes[i].parentNode = lastElement; } diff --git a/test/unit/metadata_spec.js b/test/unit/metadata_spec.js index d5e524c07..01a992702 100644 --- a/test/unit/metadata_spec.js +++ b/test/unit/metadata_spec.js @@ -146,4 +146,26 @@ describe('metadata', function() { expect(metadata.getAll()).toEqual({ 'dc:title': '\'Foo bar baz\'', }); }); + + it('should gracefully handle unbalanced end tags (issue 10410)', function() { + const data = '' + + '' + + '' + + 'Soda PDF 5' + + '' + + '2018-10-02T08:14:49-05:00' + + 'Soda PDF 5' + + '2018-10-02T08:14:49-05:00 ' + + '2018-10-02T08:14:49-05:00' + + '' + + 'uuid:00000000-1c84-3cf9-89ba-bef0e729c831' + + '' + + ''; + const metadata = new Metadata(data); + + expect(isEmptyObj(metadata.getAll())).toEqual(true); + }); });