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\'', }); + }); });