mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-08-04 05:17:24 +02:00
Merge pull request #21692 from calixteman/fix/quad-regex-xml-entities
Exclude "&" from the XML entity names
This commit is contained in:
commit
ec691130e6
@ -49,7 +49,8 @@ function isWhitespaceString(s) {
|
||||
|
||||
class XMLParserBase {
|
||||
static get _entityRegex() {
|
||||
return shadow(this, "_entityRegex", /&(?:#x([^;]+)|#([^;]+)|([^;]+));/g);
|
||||
// Entity references cannot contain "&", keeping the scan linear.
|
||||
return shadow(this, "_entityRegex", /&(?:#x([^;&]+)|#([^;&]+)|([^;&]+));/g);
|
||||
}
|
||||
|
||||
_resolveEntities(s) {
|
||||
|
||||
@ -153,4 +153,33 @@ describe("XML", function () {
|
||||
["foo", ""],
|
||||
]);
|
||||
});
|
||||
|
||||
describe("entities", function () {
|
||||
const parseText = xml =>
|
||||
new SimpleXMLParser({}).parseFromString(xml).documentElement.textContent;
|
||||
|
||||
it("should resolve the entities", function () {
|
||||
expect(
|
||||
parseText("<a><b> & "c" 'd'</a>")
|
||||
).toEqual(`<b> & "c" 'd'`);
|
||||
expect(parseText("<a>AB</a>")).toEqual("AB");
|
||||
});
|
||||
|
||||
it("should keep the unresolved entities as-is", function () {
|
||||
expect(parseText("<a>&unknown; a&b;c</a>")).toEqual("&unknown; a&b;c");
|
||||
});
|
||||
|
||||
it("should resolve an entity preceded by a bare ampersand", function () {
|
||||
expect(parseText("<a>AT&T & Co</a>")).toEqual("AT&T & Co");
|
||||
expect(parseText("<a>&&</a>")).toEqual("&&");
|
||||
});
|
||||
|
||||
it("should handle a long run of ampersands efficiently", function () {
|
||||
const text = "&".repeat(100000);
|
||||
|
||||
const startTime = performance.now();
|
||||
expect(parseText(`<a>${text}</a>`)).toEqual(text);
|
||||
expect(performance.now() - startTime).toBeLessThan(1000);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user