diff --git a/src/display/xml_parser.js b/src/display/xml_parser.js index 207f928a6e3b1..1cbb019c51306 100644 --- a/src/display/xml_parser.js +++ b/src/display/xml_parser.js @@ -321,6 +321,9 @@ class SimpleXMLParser extends XMLParserBase { // We should only have one root. const [documentElement] = this._currentFragment; + if (!documentElement) { + return undefined; // Return undefined if no root was found. + } return { documentElement, }; } diff --git a/test/unit/metadata_spec.js b/test/unit/metadata_spec.js index e3c136a468060..e818d93e5e4c4 100644 --- a/test/unit/metadata_spec.js +++ b/test/unit/metadata_spec.js @@ -13,6 +13,7 @@ * limitations under the License. */ +import { isEmptyObj } from '../../src/shared/util'; import { Metadata } from '../../src/display/metadata'; describe('metadata', function() { @@ -96,4 +97,34 @@ describe('metadata', function() { 'xap:creatortool': 'PDFCreator Version 0.9.6', }); }); + + it('should gracefully handle incomplete tags (issue 8884)', function() { + let data = '' + + '' + + '' + + '' + + '' + + '2010-03-25T11:20:09-04:00' + + '2010-03-25T11:20:09-04:00' + + '2010-03-25T11:20:09-04:00' + + '' + + '' + + 'application/pdf' + + '' + + '' + + '1' + + 'A' + + '' + + '' + + '' + + ''; + let metadata = new Metadata(data); + + expect(isEmptyObj(metadata.getAll())).toEqual(true); + }); });