Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent Metadata/XML parsing from breaking PDFDocumentProxy.getMetadata when no XML root document is found (issue 8884) #9900

Merged
merged 1 commit into from
Jul 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});