Skip to content

Commit

Permalink
fix: implement attribute normalization
Browse files Browse the repository at this point in the history
Section 3.3.3 of the XML specification. Fixes #24
  • Loading branch information
lddubeau committed Oct 11, 2019
1 parent bed38a8 commit be51114
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
9 changes: 8 additions & 1 deletion lib/saxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions test/eol-handling.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ describe("eol handling", () => {
["opentag", {
name: "moo",
attributes: {
a: "12\n 3",
a: "12 3",
},
isSelfClosing: false,
}],
["text", "\n abc\n def\r\n ghi\n\n xx\nxx\n"],
["closetag", {
name: "moo",
attributes: {
a: "12\n 3",
a: "12 3",
},
isSelfClosing: false,
}],
Expand Down Expand Up @@ -145,8 +145,8 @@ SYSTEM
["opentag", {
name: "moo",
attributes: {
a: "12\n 3",
b: "\nz\n",
a: "12 3",
b: " z ",
},
isSelfClosing: false,
}],
Expand Down Expand Up @@ -178,8 +178,8 @@ abc
["closetag", {
name: "moo",
attributes: {
a: "12\n 3",
b: "\nz\n",
a: "12 3",
b: " z ",
},
isSelfClosing: false,
}],
Expand Down

0 comments on commit be51114

Please sign in to comment.