diff --git a/lib/saxes.js b/lib/saxes.js index 552ca064..082ac41a 100644 --- a/lib/saxes.js +++ b/lib/saxes.js @@ -1055,15 +1055,21 @@ class SaxesParser { scanLoop: while (true) { switch (this.getCode()) { - case LESS: + case LESS: { this.state = S_OPEN_WAKA; - this.text += chunk.slice(start, this.prevI); - if (this.text.length !== 0) { - this.closeText(); + const { text } = this; + const slice = chunk.slice(start, this.prevI); + if (text.length !== 0) { + this.ontext(text + slice); + this.text = ""; + } + else if (slice.length !== 0) { + this.ontext(slice); } forbiddenState = FORBIDDEN_START; // eslint-disable-next-line no-labels break scanLoop; + } case AMP: this.state = S_ENTITY; this.entityReturnState = S_TEXT; @@ -1121,14 +1127,20 @@ class SaxesParser { while (true) { const code = this.getCode(); switch (code) { - case LESS: + case LESS: { this.state = S_OPEN_WAKA; - this.text += chunk.slice(start, this.prevI); - if (this.text.length !== 0) { - this.closeText(); + const { text } = this; + const slice = chunk.slice(start, this.prevI); + if (text.length !== 0) { + this.ontext(text + slice); + this.text = ""; + } + else if (slice.length !== 0) { + this.ontext(slice); } // eslint-disable-next-line no-labels break outRootLoop; + } case AMP: this.state = S_ENTITY; this.entityReturnState = S_TEXT; @@ -2049,8 +2061,10 @@ class SaxesParser { (this.state !== S_TEXT)) { this.fail("unexpected end."); } - if (this.text.length !== 0) { - this.closeText(); + const { text } = this; + if (text.length !== 0) { + this.ontext(text); + this.text = ""; } this.closed = true; this.onend(); @@ -2058,16 +2072,6 @@ class SaxesParser { return this; } - /** - * If there's text to emit ``ontext``, emit it. - * - * @private - */ - closeText() { - this.ontext(this.text); - this.text = ""; - } - /** * Resolve a namespace prefix. *