From 604241fc92f3b48d7d310610d2c1ba27ecd7f81d Mon Sep 17 00:00:00 2001 From: Louis-Dominique Dubeau Date: Fri, 6 Jul 2018 05:21:09 -0400 Subject: [PATCH] fix: raise error on CDATA before or after root --- lib/saxes.js | 9 +++++++++ 1 file changed, 9 insertions(+) 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 = "";