diff --git a/lib/saxes.js b/lib/saxes.js index 17e85b83..a1920d82 100644 --- a/lib/saxes.js +++ b/lib/saxes.js @@ -352,6 +352,15 @@ class SAXParser { case S_OPEN_WAKA_BANG: if ((this.openWakaBang + c) === CDATA) { + if (!this.sawRoot && !this.reportedTextBeforeRoot) { + this.fail("Text data outside of root node."); + this.reportedTextBeforeRoot = true; + } + + if (this.closedRoot && !this.reportedTextAfterRoot) { + this.fail("Text data outside of root node."); + this.reportedTextAfterRoot = true; + } this.emitNode("onopencdata"); this.state = S_CDATA; this.openWakaBang = "";