Skip to content

Commit

Permalink
Fix '<' or '>' in DTD comment throwing an error. (#533)
Browse files Browse the repository at this point in the history
* comment unimplemented methods

* update package for release

* Add test

* Make DocTypeReader not try to parse a tag if the '^<' is in a comment

* Remove error, don't decrement angleBracketCount if '^>' is in a comment and not an end tag

* Remove new line from xml string definition

Co-authored-by: amit kumar gupta <amitgupta.gwl@gmail.com>
  • Loading branch information
Cwazywierdo and amitguptagwl committed Jan 25, 2023
1 parent 59eb905 commit 30624d7
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 53 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
Note: If you find missing information about particular minor version, that version must have been changed without any functional change in this library.

**4.0.13 / 2023-01-07**
* preserveorder formatting (By [mdeknowis](https://github.com/mdeknowis))
* support `transformAttributeName` (By [Erik Rothoff Andersson](https://github.com/erkie))

**4.0.12 / 2022-11-19**
* fix typescript

Expand Down
2 changes: 1 addition & 1 deletion lib/fxbuilder.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/fxbuilder.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/fxp.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/fxp.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/fxparser.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/fxparser.min.js.map

Large diffs are not rendered by default.

36 changes: 15 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "fast-xml-parser",
"version": "4.0.12",
"version": "4.0.13",
"description": "Validate XML, Parse XML, Build XML without C/C++ based libraries",
"main": "./src/fxp.js",
"scripts": {
Expand Down
9 changes: 8 additions & 1 deletion spec/entities_spec.js
Expand Up @@ -128,6 +128,13 @@ describe("XMLParser Entities", function() {
expect(result).toEqual(expected);
});

it("should not throw error when DTD comments contain '<' or '>'", function() {
const xmlData = `<!DOCTYPE greeting [<!-- < > < -->]>`;

const parser = new XMLParser();
parser.parse(xmlData);
});

it("should parse attributes having '>' in value", function() {
const xmlData = `
<?xml version="1.0" encoding="UTF-8"?>
Expand Down Expand Up @@ -525,4 +532,4 @@ describe("XMLParser External Entites", function() {

expect(result).toEqual(expected);
});
});
});
4 changes: 2 additions & 2 deletions src/xmlbuilder/json2xml.js
Expand Up @@ -31,8 +31,8 @@ const defaultOptions = {
],
processEntities: true,
stopNodes: [],
transformTagName: false,
transformAttributeName: false,
// transformTagName: false,
// transformAttributeName: false,
};

function Builder(options) {
Expand Down
15 changes: 8 additions & 7 deletions src/xmlparser/DocTypeReader.js
Expand Up @@ -14,7 +14,7 @@ function readDocType(xmlData, i){
let hasBody = false, entity = false, comment = false;
let exp = "";
for(;i<xmlData.length;i++){
if (xmlData[i] === '<') {
if (xmlData[i] === '<' && !comment) {
if( hasBody &&
xmlData[i+1] === '!' &&
xmlData[i+2] === 'E' &&
Expand Down Expand Up @@ -78,14 +78,15 @@ function readDocType(xmlData, i){
if(comment){
if( xmlData[i - 1] === "-" && xmlData[i - 2] === "-"){
comment = false;
}else{
throw new Error(`Invalid XML comment in DOCTYPE`);
angleBracketsCount--;
}
}else if(entity){
parseEntityExp(exp, entities);
entity = false;
}else{
if(entity) {
parseEntityExp(exp, entities);
entity = false;
}
angleBracketsCount--;
}
angleBracketsCount--;
if (angleBracketsCount === 0) {
break;
}
Expand Down

0 comments on commit 30624d7

Please sign in to comment.