diff --git a/spec/validator_spec.js b/spec/validator_spec.js index d1cf43bc..6ad8198e 100644 --- a/spec/validator_spec.js +++ b/spec/validator_spec.js @@ -267,6 +267,15 @@ describe("XML Validator", function () { }); }); + it("should not validate XML declaration inside an element", function () { + validate("", { + InvalidXml: "XML declaration allowed only at the start of the document." + }); + validate("bar", { + InvalidXml: "XML declaration allowed only at the start of the document." + }); + }); + it("should not validate XML with prolog only", function () { validate("", { InvalidXml: "Start tag expected." diff --git a/src/validator.js b/src/validator.js index 6f9904f0..6ba4a0b8 100644 --- a/src/validator.js +++ b/src/validator.js @@ -149,7 +149,7 @@ export function validate(xmlData, options) { i = readCommentAndCDATA(xmlData, i); continue; } else if (xmlData[i + 1] === '?') { - i = readPI(xmlData, ++i); + i = readPI(xmlData, i + 2); if (i.err) return i; } else { break;