From 6cd9ff48f36da3114b721c57d12394adc671bb61 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 3 Jan 2019 21:41:52 +0100 Subject: [PATCH] Prevent errors, because of incorrect scope, in the `XMLParserBase._resolveEntities` method (issue 10407) --- src/display/xml_parser.js | 2 +- test/unit/metadata_spec.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/display/xml_parser.js b/src/display/xml_parser.js index f4080e056..03f64cd3d 100644 --- a/src/display/xml_parser.js +++ b/src/display/xml_parser.js @@ -46,7 +46,7 @@ function isWhitespaceString(s) { class XMLParserBase { _resolveEntities(s) { - return s.replace(/&([^;]+);/g, function (all, entity) { + return s.replace(/&([^;]+);/g, (all, entity) => { if (entity.substring(0, 2) === '#x') { return String.fromCharCode(parseInt(entity.substring(2), 16)); } else if (entity.substring(0, 1) === '#') { diff --git a/test/unit/metadata_spec.js b/test/unit/metadata_spec.js index e818d93e5..d5e524c07 100644 --- a/test/unit/metadata_spec.js +++ b/test/unit/metadata_spec.js @@ -127,4 +127,23 @@ describe('metadata', function() { expect(isEmptyObj(metadata.getAll())).toEqual(true); }); + + it('should correctly handle metadata containing "&apos" (issue 10407)', + function() { + const data = '' + + '' + + '' + + '' + + ''Foo bar baz'' + + ''; + const metadata = new Metadata(data); + + expect(metadata.has('dc:title')).toBeTruthy(); + expect(metadata.has('dc:qux')).toBeFalsy(); + + expect(metadata.get('dc:title')).toEqual('\'Foo bar baz\''); + expect(metadata.get('dc:qux')).toEqual(null); + + expect(metadata.getAll()).toEqual({ 'dc:title': '\'Foo bar baz\'', }); + }); });