Skip to content

Commit 090dddc

Browse files
committed
Only escape contents outside of interpolation, closes #9812
1 parent 089c470 commit 090dddc

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/elixir/lib/macro.ex

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,11 +1022,13 @@ defmodule Macro do
10221022

10231023
binary when is_binary(binary) ->
10241024
binary = inspect_no_limit(binary)
1025-
binary_part(binary, 1, byte_size(binary) - 2)
1025+
1026+
binary
1027+
|> binary_part(1, byte_size(binary) - 2)
1028+
|> escape_sigil(left)
10261029
end)
10271030

1028-
escaped = escape_sigil(parts, left)
1029-
<<left::binary, escaped::binary, right::binary>>
1031+
<<left::binary, parts::binary, right::binary>>
10301032
end
10311033

10321034
defp escape_sigil(parts, "("), do: String.replace(parts, ")", ~S"\)")

lib/elixir/test/elixir/macro_test.exs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ defmodule MacroTest do
344344
assert Macro.to_string(quote(do: ~R"\n123")) == ~S/~R"\n123"/
345345

346346
assert Macro.to_string(quote(do: ~S["'(123)'"])) == ~S/~S["'(123)'"]/
347+
assert Macro.to_string(quote(do: ~s"#{"foo"}")) == ~S/~s"#{"foo"}"/
347348

348349
assert Macro.to_string(
349350
quote do
@@ -704,6 +705,12 @@ defmodule MacroTest do
704705
assert Macro.to_string(quote(do: 'abc')) == "'abc'"
705706
end
706707

708+
test "string" do
709+
assert Macro.to_string(quote(do: "")) == ~S/""/
710+
assert Macro.to_string(quote(do: "abc")) == ~S/"abc"/
711+
assert Macro.to_string(quote(do: "#{"abc"}")) == ~S/"#{"abc"}"/
712+
end
713+
707714
test "last arg keyword list" do
708715
assert Macro.to_string(quote(do: foo([]))) == "foo([])"
709716
assert Macro.to_string(quote(do: foo(x: y))) == "foo(x: y)"

0 commit comments

Comments
 (0)