Skip to content

Commit f51ac2a

Browse files
committed
Tokenize: Fix raw triple string splitting with \ before newline
1 parent 7b560c7 commit f51ac2a

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

Tokenize/src/lexer.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,12 +523,9 @@ function lex_string_chunk(l)
523523
c = readchar(l)
524524
if c == '\\'
525525
n = 1
526-
while true
526+
while peekchar(l) == '\\'
527527
readchar(l)
528528
n += 1
529-
if peekchar(l) != '\\'
530-
break
531-
end
532529
end
533530
if peekchar(l) == state.delim && !iseven(n)
534531
readchar(l)

Tokenize/test/lexer.jl

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -349,22 +349,38 @@ end
349349

350350
@testset "string escaped newline whitespace" begin
351351
ts = collect(tokenize("\"x\\\n \ty\""))
352-
@test ts[1] ~ (T.DQUOTE , "\"")
352+
@test ts[1] ~ (T.DQUOTE, "\"")
353353
@test ts[2] ~ (T.STRING, "x")
354354
@test ts[3] ~ (T.WHITESPACE, "\\\n \t")
355355
@test ts[4] ~ (T.STRING, "y")
356-
@test ts[5] ~ (T.DQUOTE , "\"")
356+
@test ts[5] ~ (T.DQUOTE, "\"")
357+
358+
# No newline escape for raw strings
359+
ts = collect(tokenize("r\"x\\\ny\""))
360+
@test ts[1] ~ (T.IDENTIFIER , "r")
361+
@test ts[2] ~ (T.DQUOTE, "\"")
362+
@test ts[3] ~ (T.STRING, "x\\\ny")
363+
@test ts[4] ~ (T.DQUOTE , "\"")
357364
end
358365

359366
@testset "triple quoted string line splitting" begin
360367
ts = collect(tokenize("\"\"\"\nx\r\ny\rz\n\r\"\"\""))
361368
@test ts[1] ~ (T.TRIPLE_DQUOTE , "\"\"\"")
362-
@test ts[2] ~ (T.STRING, "\n")
363-
@test ts[3] ~ (T.STRING, "x\r\n")
364-
@test ts[4] ~ (T.STRING, "y\r")
365-
@test ts[5] ~ (T.STRING, "z\n")
366-
@test ts[6] ~ (T.STRING, "\r")
367-
@test ts[7] ~ (T.TRIPLE_DQUOTE, "\"\"\"")
369+
@test ts[2] ~ (T.STRING , "\n")
370+
@test ts[3] ~ (T.STRING , "x\r\n")
371+
@test ts[4] ~ (T.STRING , "y\r")
372+
@test ts[5] ~ (T.STRING , "z\n")
373+
@test ts[6] ~ (T.STRING , "\r")
374+
@test ts[7] ~ (T.TRIPLE_DQUOTE , "\"\"\"")
375+
376+
# Also for raw strings
377+
ts = collect(tokenize("r\"\"\"\nx\ny\"\"\""))
378+
@test ts[1] ~ (T.IDENTIFIER , "r")
379+
@test ts[2] ~ (T.TRIPLE_DQUOTE , "\"\"\"")
380+
@test ts[3] ~ (T.STRING , "\n")
381+
@test ts[4] ~ (T.STRING , "x\n")
382+
@test ts[5] ~ (T.STRING , "y")
383+
@test ts[6] ~ (T.TRIPLE_DQUOTE , "\"\"\"")
368384
end
369385

370386
@testset "interpolation" begin

0 commit comments

Comments
 (0)