Skip to content

Commit

Permalink
fix: harmonize error messages and initialize flags
Browse files Browse the repository at this point in the history
  • Loading branch information
lddubeau committed Jul 6, 2018
1 parent 465038b commit 9a20cad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion lib/saxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ class SAXParser {
this.state = S_BEGIN;
this.ENTITIES = Object.create(XML_ENTITIES);
this.attribList = [];
this.reportedTextBeforeRoot = false;
this.reportedTextAfterRoot = false;

// namespaces form a prototype chain.
// it always points at the current tag,
Expand Down Expand Up @@ -258,7 +260,10 @@ class SAXParser {
else if (!isWhitespace(c)) {
// have to process this as a text node.
// weird, but happens.
this.fail("Non-whitespace before first tag.");
if (!this.reportedTextBeforeRoot) {
this.fail("Text data outside of root node.");
this.reportedTextBeforeRoot = true;
}
this.textNode = c;
this.state = S_TEXT;
}
Expand Down
4 changes: 2 additions & 2 deletions test/bom.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ require(".").test({
name: "BOM outside of root, but not initial",
xml: " \uFEFF<P></P>",
expect: [
["error", "Non-whitespace before first tag.\nLine: 0\nColumn: 2\nChar: \uFEFF"],
["error", "Text data outside of root node.\nLine: 0\nColumn: 2\nChar: \uFEFF"],
["text", "\uFEFF"],
["opentagstart", { name: "P", attributes: {} }],
["opentag", { name: "P", attributes: {}, isSelfClosing: false }],
Expand All @@ -42,7 +42,7 @@ require(".").test({
name: "multiple BOMs",
xml: "\uFEFF\uFEFF<P></P>",
expect: [
["error", "Non-whitespace before first tag.\nLine: 0\nColumn: 2\nChar: \uFEFF"],
["error", "Text data outside of root node.\nLine: 0\nColumn: 2\nChar: \uFEFF"],
["text", "\uFEFF"],
["opentagstart", { name: "P", attributes: {} }],
["opentag", { name: "P", attributes: {}, isSelfClosing: false }],
Expand Down

0 comments on commit 9a20cad

Please sign in to comment.