Skip to content

Commit

Permalink
Merge pull request jshint#2264 from jacksonmj/newline-quote
Browse files Browse the repository at this point in the history
[[FIX]] Incorrect 'Unclosed string' when the closing quote is the first character after a newline
  • Loading branch information
rwaldron committed Apr 10, 2015
2 parents 564fb18 + b804e65 commit 135cefa
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
50 changes: 26 additions & 24 deletions src/lex.js
Expand Up @@ -1147,7 +1147,7 @@ Lexer.prototype = {
this.skip();

while (this.peek() !== quote) {
while (this.peek() === "") { // End Of Line
if (this.peek() === "") { // End Of Line

// If an EOL is not preceded by a backslash, show a warning
// and proceed like it was a legit multi-line string where
Expand Down Expand Up @@ -1200,33 +1200,35 @@ Lexer.prototype = {
quote: quote
};
}
}

allowNewLine = false;
var char = this.peek();
var jump = 1; // A length of a jump, after we're done
// parsing this character.
} else { // Any character other than End Of Line

if (char < " ") {
// Warn about a control character in a string.
this.trigger("warning", {
code: "W113",
line: this.line,
character: this.char,
data: [ "<non-printable>" ]
});
}
allowNewLine = false;
var char = this.peek();
var jump = 1; // A length of a jump, after we're done
// parsing this character.

// Special treatment for some escaped characters.
if (char === "\\") {
var parsed = this.scanEscapeSequence(checks);
char = parsed.char;
jump = parsed.jump;
allowNewLine = parsed.allowNewLine;
}
if (char < " ") {
// Warn about a control character in a string.
this.trigger("warning", {
code: "W113",
line: this.line,
character: this.char,
data: [ "<non-printable>" ]
});
}

value += char;
this.skip(jump);
// Special treatment for some escaped characters.
if (char === "\\") {
var parsed = this.scanEscapeSequence(checks);
char = parsed.char;
jump = parsed.jump;
allowNewLine = parsed.allowNewLine;
}

value += char;
this.skip(jump);
}
}

this.skip();
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/fixtures/strings.js
Expand Up @@ -25,3 +25,6 @@ function octal_strictmode() {
var test = "\033\t";
test = "\0"; // Regression for false positives on \0
}

test = "closing quote on next line\
";
1 change: 1 addition & 0 deletions tests/unit/options.js
Expand Up @@ -1297,6 +1297,7 @@ exports.strings = function (test) {
.addError(14, "Bad escaping of EOL. Use option multistr if needed.")
.addError(15, "Unclosed string.")
.addError(25, "Octal literals are not allowed in strict mode.")
.addError(29, "Bad escaping of EOL. Use option multistr if needed.")
.test(src, { es3: true });

test.done();
Expand Down

0 comments on commit 135cefa

Please sign in to comment.