Skip to content

Commit

Permalink
Merge pull request #9900 from Snuffleupagus/issue-8884
Browse files Browse the repository at this point in the history
Prevent Metadata/XML parsing from breaking `PDFDocumentProxy.getMetadata` when no XML root document is found (issue 8884)
  • Loading branch information
timvandermeij authored Jul 22, 2018
2 parents 7e13977 + 8ec99b2 commit 2ce489c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/display/xml_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, };
}

Expand Down
31 changes: 31 additions & 0 deletions test/unit/metadata_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* limitations under the License.
*/

import { isEmptyObj } from '../../src/shared/util';
import { Metadata } from '../../src/display/metadata';

describe('metadata', function() {
Expand Down Expand Up @@ -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 = '<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d' +
'<x:xmpmeta xmlns:x="adobe:ns:meta/">' +
'<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">' +
'<rdf:Description rdf:about=""' +
'xmlns:pdfx="http://ns.adobe.com/pdfx/1.3/">' +
'</rdf:Description>' +
'<rdf:Description rdf:about=""' +
'xmlns:xap="http://ns.adobe.com/xap/1.0/">' +
'<xap:ModifyDate>2010-03-25T11:20:09-04:00</xap:ModifyDate>' +
'<xap:CreateDate>2010-03-25T11:20:09-04:00</xap:CreateDate>' +
'<xap:MetadataDate>2010-03-25T11:20:09-04:00</xap:MetadataDate>' +
'</rdf:Description>' +
'<rdf:Description rdf:about=""' +
'xmlns:dc="http://purl.org/dc/elements/1.1/">' +
'<dc:format>application/pdf</dc:format>' +
'</rdf:Description>' +
'<rdf:Description rdf:about=""' +
'xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/">' +
'<pdfaid:part>1</pdfaid:part>' +
'<pdfaid:conformance>A</pdfaid:conformance>' +
'</rdf:Description>' +
'</rdf:RDF>' +
'</x:xmpmeta>' +
'<?xpacket end="w"?>';
let metadata = new Metadata(data);

expect(isEmptyObj(metadata.getAll())).toEqual(true);
});
});

0 comments on commit 2ce489c

Please sign in to comment.