diff --git a/lib/saxes.js b/lib/saxes.js index aa5bca16..e127fc57 100644 --- a/lib/saxes.js +++ b/lib/saxes.js @@ -1907,8 +1907,10 @@ class SaxesParser { this.state = S_ENTITY; this.entityReturnState = S_ATTRIB_VALUE_QUOTED; return; + case NL: case NL_LIKE: - this.text += `${chunk.slice(start, this.prevI)}\n`; + case TAB: + this.text += `${chunk.slice(start, this.prevI)} `; start = this.i; break; case LESS: @@ -1947,6 +1949,11 @@ class SaxesParser { /** @private */ sAttribValueUnquoted() { + // We don't do anything regarding EOL or space handling for unquoted + // attributes. We already have failed by the time we get here, and the + // contract that saxes upholds states that upon failure, it is not safe to + // rely on the data passed to event handlers (other than + // ``onerror``). Passing "bad" data is not a problem. const c = this.captureTo(ATTRIB_VALUE_UNQUOTED_TERMINATOR); switch (c) { case AMP: diff --git a/test/eol-handling.js b/test/eol-handling.js index 0565886a..c8dd3933 100644 --- a/test/eol-handling.js +++ b/test/eol-handling.js @@ -25,7 +25,7 @@ describe("eol handling", () => { ["opentag", { name: "moo", attributes: { - a: "12\n 3", + a: "12 3", }, isSelfClosing: false, }], @@ -33,7 +33,7 @@ describe("eol handling", () => { ["closetag", { name: "moo", attributes: { - a: "12\n 3", + a: "12 3", }, isSelfClosing: false, }], @@ -145,8 +145,8 @@ SYSTEM ["opentag", { name: "moo", attributes: { - a: "12\n 3", - b: "\nz\n", + a: "12 3", + b: " z ", }, isSelfClosing: false, }], @@ -178,8 +178,8 @@ abc ["closetag", { name: "moo", attributes: { - a: "12\n 3", - b: "\nz\n", + a: "12 3", + b: " z ", }, isSelfClosing: false, }],