diff --git a/lib/saxes.js b/lib/saxes.js index 0a8ea1a5..ba1e67ec 100644 --- a/lib/saxes.js +++ b/lib/saxes.js @@ -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, @@ -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; } diff --git a/test/bom.js b/test/bom.js index e238f948..82147eaa 100644 --- a/test/bom.js +++ b/test/bom.js @@ -29,7 +29,7 @@ require(".").test({ name: "BOM outside of root, but not initial", xml: " \uFEFF
", 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 }], @@ -42,7 +42,7 @@ require(".").test({ name: "multiple BOMs", xml: "\uFEFF\uFEFF", 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 }],