Skip to content
Open
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
11 changes: 11 additions & 0 deletions spec/validator_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,17 @@ attribute2="attribute2"
validate('<rootNode>jekyll &abcdefghij1234567890;</rootNode>');
validate('<rootNode>jekyll &abcdefghij1234567890a;</rootNode>', error); // limit to 20 chars
});

it("should not validate XML with raw ']]>' in element text", function () {
const error = {
InvalidChar: "char ']]>' is not expected."
};
validate("<a>]]></a>", error, 1, 4);
validate("<root>hello ]]> world</root>", error, 1, 13);
validate("<a><![CDATA[inside]]>after]]></a>", error, 1, 27);
validate("<a>]]&gt;</a>");
validate("<a attr=']]>'>ok</a>");
});
});

describe("should not validate XML documents with multiple root nodes", () => {
Expand Down
2 changes: 2 additions & 0 deletions src/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ export function validate(xmlData, options) {
if (afterAmp == -1)
return getErrorObject('InvalidChar', "char '&' is not expected.", getLineNumberForPosition(xmlData, i));
i = afterAmp;
} else if (xmlData[i] === ']' && xmlData[i + 1] === ']' && xmlData[i + 2] === '>') {
return getErrorObject('InvalidChar', "char ']]>' is not expected.", getLineNumberForPosition(xmlData, i));
} else {
if (reachedRoot === true && !isWhiteSpace(xmlData[i])) {
return getErrorObject('InvalidXml', "Extra text at the end", getLineNumberForPosition(xmlData, i));
Expand Down