Skip to content

Commit 96b3c5d

Browse files
authored
fix #41330: backslash not escaping \r\n (#41333)
1 parent d96f4c7 commit 96b3c5d

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

base/shell.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,12 @@ function shell_parse(str::AbstractString, interpolate::Bool=true;
8888
in_double_quotes = !in_double_quotes
8989
i = consume_upto!(arg, s, i, j)
9090
elseif !in_single_quotes && c == '\\'
91-
if !isempty(st) && peek(st)[2] == '\n'
91+
if !isempty(st) && peek(st)[2] in ('\n', '\r')
9292
i = consume_upto!(arg, s, i, j) + 1
93-
_ = popfirst!(st)
93+
if popfirst!(st)[2] == '\r' && peek(st)[2] == '\n'
94+
i += 1
95+
popfirst!(st)
96+
end
9497
elseif in_double_quotes
9598
isempty(st) && error("unterminated double quote")
9699
k, c′ = peek(st)

src/julia-parser.scm

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2365,8 +2365,11 @@
23652365
(loop (read-char p) b e 0))))
23662366
(let ((nxch (not-eof-for delim (read-char p))))
23672367
(write-char #\\ b)
2368-
(write-char nxch b)
2369-
(loop (read-char p) b e 0))))
2368+
(if (eqv? nxch #\return)
2369+
(loop nxch b e 0)
2370+
(begin
2371+
(write-char nxch b)
2372+
(loop (read-char p) b e 0))))))
23702373

23712374
((and (eqv? c #\$) (not raw))
23722375
(let* ((ex (parse-interpolate s))

test/syntax.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,3 +2930,10 @@ end
29302930

29312931
# issue #41253
29322932
@test (function (::Dict{}); end)(Dict()) === nothing
2933+
2934+
@testset "issue #41330" begin
2935+
@test Meta.parse("\"a\\\r\nb\"") == "ab"
2936+
@test Meta.parse("\"a\\\rb\"") == "ab"
2937+
@test eval(Meta.parse("`a\\\r\nb`")) == `ab`
2938+
@test eval(Meta.parse("`a\\\rb`")) == `ab`
2939+
end

0 commit comments

Comments
 (0)