Skip to content

Commit

Permalink
fix JuliaLang#41330: backslash not escaping \r\n (JuliaLang#41333)
Browse files Browse the repository at this point in the history
  • Loading branch information
simeonschaub authored and johanmon committed Jul 5, 2021
1 parent 68e335f commit c0e57a4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
7 changes: 5 additions & 2 deletions base/shell.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
7 changes: 7 additions & 0 deletions test/syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c0e57a4

Please sign in to comment.