Skip to content

Commit ebbe2bd

Browse files
authored
SONARPY-623 Fix handling of backslash followed by empty line (SonarSource#641)
1 parent 884f4bb commit ebbe2bd

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

python-frontend/src/main/java/org/sonar/python/lexer/NewLineChannel.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public boolean consume(CodeReader code, Lexer output) {
4646
if ((ch == '\\') && isNewLine(code.charAt(1))) {
4747
// Explicit line joining
4848
code.pop();
49-
joinLines(code);
49+
consumeEOL(code);
50+
lexerState.joined = true;
5051
return true;
5152
}
5253

python-frontend/src/test/java/org/sonar/python/lexer/PythonLexerTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ public void explicit_line_joining() {
285285
assertThat(lexer.lex("line\\\r\nline"), not(hasToken(PythonTokenType.NEWLINE)));
286286
assertThat(lexer.lex("line\\\rline"), not(hasToken(PythonTokenType.NEWLINE)));
287287
assertThat(lexer.lex("line\\\nline"), not(hasToken(PythonTokenType.NEWLINE)));
288+
assertThat(lexer.lex("line\\\n\nline"), hasToken(PythonTokenType.NEWLINE));
288289

289290
assertThat(lexer.lex("line\\\n line")).hasSize(3);
290291
}

0 commit comments

Comments
 (0)