From 96b3c5d733592ff1523a7c75db32d016761d7757 Mon Sep 17 00:00:00 2001 From: Simeon Schaub Date: Mon, 28 Jun 2021 21:42:13 +0200 Subject: [PATCH] fix #41330: backslash not escaping `\r\n` (#41333) --- base/shell.jl | 7 +++++-- src/julia-parser.scm | 7 +++++-- test/syntax.jl | 7 +++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/base/shell.jl b/base/shell.jl index a5b25fc63ea44..475a0871d8355 100644 --- a/base/shell.jl +++ b/base/shell.jl @@ -88,9 +88,12 @@ function shell_parse(str::AbstractString, interpolate::Bool=true; in_double_quotes = !in_double_quotes i = consume_upto!(arg, s, i, j) elseif !in_single_quotes && c == '\\' - if !isempty(st) && peek(st)[2] == '\n' + if !isempty(st) && peek(st)[2] in ('\n', '\r') i = consume_upto!(arg, s, i, j) + 1 - _ = popfirst!(st) + if popfirst!(st)[2] == '\r' && peek(st)[2] == '\n' + i += 1 + popfirst!(st) + end elseif in_double_quotes isempty(st) && error("unterminated double quote") k, c′ = peek(st) diff --git a/src/julia-parser.scm b/src/julia-parser.scm index 3a5dfad9293bd..fb29cb5005fba 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -2365,8 +2365,11 @@ (loop (read-char p) b e 0)))) (let ((nxch (not-eof-for delim (read-char p)))) (write-char #\\ b) - (write-char nxch b) - (loop (read-char p) b e 0)))) + (if (eqv? nxch #\return) + (loop nxch b e 0) + (begin + (write-char nxch b) + (loop (read-char p) b e 0)))))) ((and (eqv? c #\$) (not raw)) (let* ((ex (parse-interpolate s)) diff --git a/test/syntax.jl b/test/syntax.jl index 6e3ec82ca3e81..9ef8c033c14ad 100644 --- a/test/syntax.jl +++ b/test/syntax.jl @@ -2930,3 +2930,10 @@ end # issue #41253 @test (function (::Dict{}); end)(Dict()) === nothing + +@testset "issue #41330" begin + @test Meta.parse("\"a\\\r\nb\"") == "ab" + @test Meta.parse("\"a\\\rb\"") == "ab" + @test eval(Meta.parse("`a\\\r\nb`")) == `ab` + @test eval(Meta.parse("`a\\\rb`")) == `ab` +end