diff --git a/spec/validator_spec.js b/spec/validator_spec.js
index 0d07e227..60869857 100644
--- a/spec/validator_spec.js
+++ b/spec/validator_spec.js
@@ -378,6 +378,17 @@ attribute2="attribute2"
validate('jekyll &abcdefghij1234567890;');
validate('jekyll &abcdefghij1234567890a;', error); // limit to 20 chars
});
+
+ it("should not validate XML with raw ']]>' in element text", function () {
+ const error = {
+ InvalidChar: "char ']]>' is not expected."
+ };
+ validate("]]>", error, 1, 4);
+ validate("hello ]]> world", error, 1, 13);
+ validate("after]]>", error, 1, 27);
+ validate("]]>");
+ validate("ok");
+ });
});
describe("should not validate XML documents with multiple root nodes", () => {
diff --git a/src/validator.js b/src/validator.js
index 6f9904f0..2309aa5e 100644
--- a/src/validator.js
+++ b/src/validator.js
@@ -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));