diff --git a/lib/saxes.js b/lib/saxes.js index 2af7fcb2..abbe4988 100644 --- a/lib/saxes.js +++ b/lib/saxes.js @@ -1168,6 +1168,9 @@ class SaxesParser { // a state handler cannot return ``undefined``. That's why we don't test // for it. const c = this.getCode(); + if (this.text.length !== 0) { + this.closeText(); + } // either a /, ?, !, or text is coming next. if (isNameStartChar(c)) { this.state = S_OPEN_TAG; @@ -1222,9 +1225,6 @@ class SaxesParser { if (this.doctype || this.sawRoot) { this.fail("inappropriately located doctype declaration."); } - if (this.text.length !== 0) { - this.closeText(); - } this.openWakaBang = ""; break; default: @@ -1387,9 +1387,6 @@ class SaxesParser { const c = this.getCode(); if (c === MINUS) { this.state = S_COMMENT_ENDED; - if (this.text.length !== 0) { - this.closeText(); - } this.oncomment(this.comment); this.comment = ""; } @@ -1438,9 +1435,6 @@ class SaxesParser { const c = this.getCode(); switch (c) { case GREATER: - if (this.text.length !== 0) { - this.closeText(); - } this.oncdata(this.cdata); this.cdata = ""; this.state = S_TEXT; @@ -1680,9 +1674,6 @@ class SaxesParser { if (this.piTarget.trim().toLowerCase() === "xml") { this.fail("the XML declaration must appear at the start of the document."); } - if (this.text.length !== 0) { - this.closeText(); - } this.onprocessinginstruction({ target: this.piTarget, body: this.piBody, @@ -1721,9 +1712,6 @@ class SaxesParser { tag.ns = Object.create(null); } - if (this.text.length !== 0) { - this.closeText(); - } this.onopentagstart(tag); this.sawRoot = true; if (!this.fragmentOpt && this.closedRoot) { @@ -2250,9 +2238,6 @@ class SaxesParser { let l = tags.length; while (l-- > 0) { const tag = this.tag = tags.pop(); - if (this.text.length !== 0) { - this.closeText(); - } this.onclosetag(tag); if (tag.name === name) { break; diff --git a/test/issue-86.js b/test/issue-86.js index 051150a5..d68e92f1 100644 --- a/test/issue-86.js +++ b/test/issue-86.js @@ -31,6 +31,10 @@ require(".").test({ isSelfClosing: false, }, ], + [ + "text", + "de", + ], [ "error", "1:19: text data outside of root node.", @@ -39,10 +43,6 @@ require(".").test({ "error", "1:20: unexpected end.", ], - [ - "text", - "de", - ], ], opt: {}, }); diff --git a/test/parser-position.js b/test/parser-position.js index ccf17c1e..116a7c46 100644 --- a/test/parser-position.js +++ b/test/parser-position.js @@ -38,7 +38,7 @@ describe("parser position", () => { ["