Skip to content

Commit 9a880b8

Browse files
juliangilbeyJulian Gilbey
andauthored
Merge pull request from GHSA-gpv5-7x3g-ghjv
Co-authored-by: Julian Gilbey <[email protected]>
1 parent ecf6016 commit 9a880b8

File tree

2 files changed

+50
-7
lines changed

2 files changed

+50
-7
lines changed

spec/entities_spec.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ describe("XMLParser Entities", function() {
376376

377377
expect(result).toEqual(expected);
378378
});
379+
379380
it("should throw error if an entity name contains special char", function() {
380381
const xmlData = `
381382
<?xml version="1.0" encoding="UTF-8"?>
@@ -392,7 +393,48 @@ describe("XMLParser Entities", function() {
392393
expect(() =>{
393394
const parser = new XMLParser(options);
394395
parser.parse(xmlData);
395-
}).toThrowError("Invalid character $ in entity name")
396+
}).toThrowError("Invalid entity name nj$")
397+
});
398+
399+
it("should allow localised entity names", function() {
400+
const xmlData = `
401+
<?xml version="1.0" encoding="UTF-8"?>
402+
403+
<!DOCTYPE note [
404+
<!ENTITY ሀሎ "Amharic hello!">
405+
<!ENTITY Здраво "Macedonian hello.">
406+
]>
407+
408+
<note>
409+
<heading>Reminder</heading>
410+
<body attr="&ሀሎ;">Don't forget me this weekend! &Здраво;</body>
411+
</note> `;
412+
413+
const expected = {
414+
"?xml": {
415+
"version": "1.0",
416+
"encoding": "UTF-8"
417+
},
418+
"note": {
419+
"heading": "Reminder",
420+
"body": {
421+
"#text": "Don't forget me this weekend! Macedonian hello.",
422+
"attr": "Amharic hello!"
423+
}
424+
}
425+
};
426+
427+
const options = {
428+
attributeNamePrefix: "",
429+
ignoreAttributes: false,
430+
processEntities: true,
431+
htmlEntities: true
432+
};
433+
const parser = new XMLParser(options);
434+
let result = parser.parse(xmlData);
435+
// console.log(JSON.stringify(result,null,4));
436+
437+
expect(result).toEqual(expected);
396438
});
397439
});
398440

src/xmlparser/DocTypeReader.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const util = require('../util');
2+
13
//TODO: handle comments
24
function readDocType(xmlData, i){
35

@@ -145,11 +147,10 @@ function isNotation(xmlData, i){
145147
const specialChar = "!?\\\/[]$%{}^&*()<>|+";
146148

147149
function validateEntityName(name){
148-
for (let i = 0; i < specialChar.length; i++) {
149-
const ch = specialChar[i];
150-
if(name.indexOf(ch) !== -1) throw new Error(`Invalid character ${ch} in entity name`);
151-
}
152-
return name;
150+
if (util.isName(name))
151+
return name;
152+
else
153+
throw new Error(`Invalid entity name ${name}`);
153154
}
154155

155-
module.exports = readDocType;
156+
module.exports = readDocType;

0 commit comments

Comments
 (0)