diff --git a/lib/saxes.js b/lib/saxes.js index 0d8ee5b5..2af7fcb2 100644 --- a/lib/saxes.js +++ b/lib/saxes.js @@ -296,7 +296,6 @@ class SaxesParser { this.openWakaBang = ""; this.text = ""; this.name = ""; - this.doctype = ""; this.piTarget = ""; this.piBody = ""; this.entity = ""; @@ -1223,6 +1222,9 @@ class SaxesParser { if (this.doctype || this.sawRoot) { this.fail("inappropriately located doctype declaration."); } + if (this.text.length !== 0) { + this.closeText(); + } this.openWakaBang = ""; break; default: @@ -1236,20 +1238,18 @@ class SaxesParser { /** @private */ sDoctype() { - const c = this.captureTo(DOCTYPE_TERMINATOR, "doctype"); + const c = this.captureTo(DOCTYPE_TERMINATOR, "text"); switch (c) { case GREATER: + this.ondoctype(this.text); + this.text = ""; this.state = S_TEXT; - if (this.text.length !== 0) { - this.closeText(); - } - this.ondoctype(this.doctype); this.doctype = true; // just remember that we saw it. break; case EOC: break; default: - this.doctype += String.fromCodePoint(c); + this.text += String.fromCodePoint(c); if (c === OPEN_BRACKET) { this.state = S_DTD; } @@ -1263,8 +1263,8 @@ class SaxesParser { /** @private */ sDoctypeQuote() { const { q } = this; - if (this.captureToChar(q, "doctype")) { - this.doctype += String.fromCodePoint(q); + if (this.captureToChar(q, "text")) { + this.text += String.fromCodePoint(q); this.q = null; this.state = S_DOCTYPE; } @@ -1272,12 +1272,12 @@ class SaxesParser { /** @private */ sDTD() { - const c = this.captureTo(DTD_TERMINATOR, "doctype"); + const c = this.captureTo(DTD_TERMINATOR, "text"); if (c === EOC) { return; } - this.doctype += String.fromCodePoint(c); + this.text += String.fromCodePoint(c); if (c === CLOSE_BRACKET) { this.state = S_DOCTYPE; } @@ -1293,8 +1293,8 @@ class SaxesParser { /** @private */ sDTDQuoted() { const { q } = this; - if (this.captureToChar(q, "doctype")) { - this.doctype += String.fromCodePoint(q); + if (this.captureToChar(q, "text")) { + this.text += String.fromCodePoint(q); this.state = S_DTD; this.q = null; } @@ -1303,7 +1303,7 @@ class SaxesParser { /** @private */ sDTDOpenWaka() { const c = this.getCode(); - this.doctype += String.fromCodePoint(c); + this.text += String.fromCodePoint(c); switch (c) { case BANG: this.state = S_DTD_OPEN_WAKA_BANG; @@ -1321,7 +1321,7 @@ class SaxesParser { sDTDOpenWakaBang() { const char = String.fromCodePoint(this.getCode()); const owb = this.openWakaBang += char; - this.doctype += char; + this.text += char; if (owb !== "-") { this.state = owb === "--" ? S_DTD_COMMENT : S_DTD; this.openWakaBang = ""; @@ -1330,8 +1330,8 @@ class SaxesParser { /** @private */ sDTDComment() { - if (this.captureToChar(MINUS, "doctype")) { - this.doctype += "-"; + if (this.captureToChar(MINUS, "text")) { + this.text += "-"; this.state = S_DTD_COMMENT_ENDING; } } @@ -1339,14 +1339,14 @@ class SaxesParser { /** @private */ sDTDCommentEnding() { const c = this.getCode(); - this.doctype += String.fromCodePoint(c); + this.text += String.fromCodePoint(c); this.state = c === MINUS ? S_DTD_COMMENT_ENDED : S_DTD_COMMENT; } /** @private */ sDTDCommentEnded() { const c = this.getCode(); - this.doctype += String.fromCodePoint(c); + this.text += String.fromCodePoint(c); if (c === GREATER) { this.state = S_DTD; } @@ -1360,8 +1360,8 @@ class SaxesParser { /** @private */ sDTDPI() { - if (this.captureToChar(QUESTION, "doctype")) { - this.doctype += "?"; + if (this.captureToChar(QUESTION, "text")) { + this.text += "?"; this.state = S_DTD_PI_ENDING; } } @@ -1369,7 +1369,7 @@ class SaxesParser { /** @private */ sDTDPIEnding() { const c = this.getCode(); - this.doctype += String.fromCodePoint(c); + this.text += String.fromCodePoint(c); if (c === GREATER) { this.state = S_DTD; }