diff --git a/lib/saxes.js b/lib/saxes.js index 84bb0215..0b8f3757 100644 --- a/lib/saxes.js +++ b/lib/saxes.js @@ -405,7 +405,7 @@ class SaxesParser { this.line = 1; /** The column the parser is currently looking at. */ - this.column = 0; + this.positionAtNewLine = 0; this.fileName = this.opt.fileName; this.onready(); @@ -416,6 +416,10 @@ class SaxesParser { return this.chunkPosition + this.i; } + get column() { + return this.position - this.positionAtNewLine; + } + /* eslint-disable class-methods-use-this */ /** * Event handler for text data. The default implementation is a no-op. @@ -610,8 +614,7 @@ class SaxesParser { this.i++; if (code < 0xD800) { - if (code >= SPACE) { - this.column++; + if (code >= SPACE || code === TAB) { return code; } @@ -630,13 +633,9 @@ class SaxesParser { /* yes, fall through */ case NL: this.line++; - this.column = 0; + this.positionAtNewLine = this.position; return NL; - case TAB: - this.column++; - return TAB; default: - this.column++; // If we get here, then code < SPACE and it is not NL CR or TAB. this.fail("disallowed character."); return code; @@ -644,7 +643,6 @@ class SaxesParser { } if (code > 0xDBFF) { - this.column++; // This is a specialized version of isChar10 that takes into account // that in this context code > 0xDBFF and code <= 0xFFFF. So it does not // test cases that don't need testing. @@ -662,7 +660,6 @@ class SaxesParser { const final = 0x10000 + ((code - 0xD800) * 0x400) + (chunk.charCodeAt(i + 1) - 0xDC00); - this.column += 2; this.i++; // This is a specialized version of isChar10 that takes into account that in @@ -693,8 +690,7 @@ class SaxesParser { this.i++; if (code < 0xD800) { - if ((code > 0x1F && code < 0x7F) || code > 0x9F) { - this.column++; + if ((code > 0x1F && code < 0x7F) || code > 0x9F || code === TAB) { return code; } @@ -715,20 +711,15 @@ class SaxesParser { case NEL: // 0x85 case LS: // Ox2028 this.line++; - this.column = 0; + this.positionAtNewLine = this.position; return NL; - case TAB: // 9 - this.column++; - return TAB; default: - this.column++; this.fail("disallowed character."); return code; } } if (code > 0xDBFF) { - this.column++; // This is a specialized version of isCharAndNotRestricted that takes into // account that in this context code > 0xDBFF and code <= 0xFFFF. So it // does not test cases that don't need testing. @@ -746,7 +737,6 @@ class SaxesParser { const final = 0x10000 + ((code - 0xD800) * 0x400) + (chunk.charCodeAt(i + 1) - 0xDC00); - this.column += 2; this.i++; // This is a specialized version of isCharAndNotRestricted that takes into @@ -924,11 +914,9 @@ class SaxesParser { // If the initial character is 0xFEFF, ignore it. if (c === 0xFEFF) { this.i++; - this.column++; } else if (isS(c)) { this.i++; - this.column++; // An XML declaration cannot appear after initial spaces. this.xmlDeclPossible = false; } diff --git a/test/trailing-non-whitespace.js b/test/trailing-non-whitespace.js index f9a8d5ec..27318ca7 100644 --- a/test/trailing-non-whitespace.js +++ b/test/trailing-non-whitespace.js @@ -19,7 +19,7 @@ require(".").test({ attributes: {}, isSelfClosing: false, }], - ["error", "1:36: text data outside of root node."], + ["error", "1:37: text data outside of root node."], ["text", " to monkey land"], ["end", undefined], ["ready", undefined],