Skip to content

Commit

Permalink
fix: validator bag when closing tag is not opened. (#647)
Browse files Browse the repository at this point in the history
* fix validator bag if tag is not opened.

* fix test
  • Loading branch information
RyosukeFukatani authored Mar 24, 2024
1 parent 3ab1b3b commit a96b968
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions spec/validator_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ describe("XML Validator", function () {
});
});

it("should not validate xml with unexpected closing tag", function () {
validate("</rootNode>", {
InvalidTag: "Closing tag 'rootNode' has not been opened."
});
});

it("should validate xml with comment", function () {
validate("<rootNode><!-- <tag> - - --><tag>1</tag><tag>val</tag></rootNode>");
});
Expand Down
2 changes: 2 additions & 0 deletions src/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ exports.validate = function (xmlData, options) {
return getErrorObject('InvalidTag', "Closing tag '"+tagName+"' doesn't have proper closing.", getLineNumberForPosition(xmlData, i));
} else if (attrStr.trim().length > 0) {
return getErrorObject('InvalidTag', "Closing tag '"+tagName+"' can't have attributes or invalid starting.", getLineNumberForPosition(xmlData, tagStartPos));
} else if (tags.length === 0) {
return getErrorObject('InvalidTag', "Closing tag '"+tagName+"' has not been opened.", getLineNumberForPosition(xmlData, tagStartPos));
} else {
const otg = tags.pop();
if (tagName !== otg.tagName) {
Expand Down

0 comments on commit a96b968

Please sign in to comment.