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: validator bag when closing tag is not opened. #647

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