Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix '<' or '>' in DTD comment throwing an error. #533

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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