Skip to content

Commit

Permalink
Merge pull request from GHSA-gpv5-7x3g-ghjv
Browse files Browse the repository at this point in the history
Co-authored-by: Julian Gilbey <jdg@debian.org>
  • Loading branch information
juliangilbey and Julian Gilbey authored Jun 13, 2023
1 parent ecf6016 commit 9a880b8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
44 changes: 43 additions & 1 deletion spec/entities_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ describe("XMLParser Entities", function() {

expect(result).toEqual(expected);
});

it("should throw error if an entity name contains special char", function() {
const xmlData = `
<?xml version="1.0" encoding="UTF-8"?>
Expand All @@ -392,7 +393,48 @@ describe("XMLParser Entities", function() {
expect(() =>{
const parser = new XMLParser(options);
parser.parse(xmlData);
}).toThrowError("Invalid character $ in entity name")
}).toThrowError("Invalid entity name nj$")
});

it("should allow localised entity names", function() {
const xmlData = `
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE note [
<!ENTITY ሀሎ "Amharic hello!">
<!ENTITY Здраво "Macedonian hello.">
]>
<note>
<heading>Reminder</heading>
<body attr="&ሀሎ;">Don't forget me this weekend! &Здраво;</body>
</note> `;

const expected = {
"?xml": {
"version": "1.0",
"encoding": "UTF-8"
},
"note": {
"heading": "Reminder",
"body": {
"#text": "Don't forget me this weekend! Macedonian hello.",
"attr": "Amharic hello!"
}
}
};

const options = {
attributeNamePrefix: "",
ignoreAttributes: false,
processEntities: true,
htmlEntities: true
};
const parser = new XMLParser(options);
let result = parser.parse(xmlData);
// console.log(JSON.stringify(result,null,4));

expect(result).toEqual(expected);
});
});

Expand Down
13 changes: 7 additions & 6 deletions src/xmlparser/DocTypeReader.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const util = require('../util');

//TODO: handle comments
function readDocType(xmlData, i){

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

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

module.exports = readDocType;
module.exports = readDocType;

1 comment on commit 9a880b8

@alfaproject
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amitguptagwl any chance for a release?

Please sign in to comment.