Skip to content

Commit

Permalink
fix #35305, need escaping when printing string macro calls
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Mar 30, 2020
1 parent cdc5e79 commit b6dd448
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 4 additions & 2 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1500,11 +1500,13 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::In
is_core_macro(args[1], "@big_str")
print(io, args[3])
# x"y" and x"y"z
elseif isa(args[1], Symbol) &&
elseif isa(args[1], Symbol) && nargs >= 3 && isa(args[3], String) &&
startswith(string(args[1]::Symbol), "@") &&
endswith(string(args[1]::Symbol), "_str")
s = string(args[1]::Symbol)
print(io, s[2:prevind(s,end,4)], "\"", args[3], "\"")
print(io, s[2:prevind(s,end,4)], "\"")
escape_raw_string(io, args[3])
print(io, "\"")
if nargs == 4
print(io, args[4])
end
Expand Down
3 changes: 3 additions & 0 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,9 @@ z856739 = [:a, :b]
@test sprint(show, Meta.parse("a\"b\"c")) == ":(a\"b\"c)"
@test sprint(show, Meta.parse("aa\"b\"")) == ":(aa\"b\")"
@test sprint(show, Meta.parse("a\"b\"cc")) == ":(a\"b\"cc)"
@test sprint(show, Meta.parse("a\"\"\"issue \"35305\" \"\"\"")) == ":(a\"issue \\\"35305\\\" \")"
@test sprint(show, Meta.parse("a\"\$\"")) == ":(a\"\$\")"
@test sprint(show, Meta.parse("a\"\\b\"")) == ":(a\"\\b\")"
# 11111111111111111111, 0xfffffffffffffffff, 1111...many digits...
@test sprint(show, Meta.parse("11111111111111111111")) == ":(11111111111111111111)"
# @test_repr "Base.@int128_str \"11111111111111111111\""
Expand Down

0 comments on commit b6dd448

Please sign in to comment.