From d0bd8692ddaea99793c444c61e21d977fa3435cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 14 Mar 2018 10:10:40 +0100 Subject: Do not escape quoted keywords on formatting, closes #7451 --- lib/elixir/lib/code/formatter.ex | 11 ++++++++++- lib/elixir/test/elixir/code_formatter/containers_test.exs | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/elixir/lib/code/formatter.ex b/lib/elixir/lib/code/formatter.ex index fe37663f9..c1ee99e23 100644 --- a/lib/elixir/lib/code/formatter.ex +++ b/lib/elixir/lib/code/formatter.ex @@ -555,7 +555,16 @@ defmodule Code.Formatter do {left, state} = case left_arg do {:__block__, _, [atom]} when is_atom(atom) -> - {atom |> Code.Identifier.inspect_as_key() |> string(), state} + key = + case Code.Identifier.classify(atom) do + type when type in [:callable_local, :callable_operator, :not_callable] -> + IO.iodata_to_binary([Atom.to_string(atom), ?:]) + + _ -> + IO.iodata_to_binary([?", Atom.to_string(atom), ?", ?:]) + end + + {string(key), state} {{:., _, [:erlang, :binary_to_atom]}, _, [{:<<>>, _, entries}, :utf8]} -> interpolation_to_algebra(entries, @double_quote, state, "\"", "\":") diff --git a/lib/elixir/test/elixir/code_formatter/containers_test.exs b/lib/elixir/test/elixir/code_formatter/containers_test.exs index 89989d78f..0c3b5fc27 100644 --- a/lib/elixir/test/elixir/code_formatter/containers_test.exs +++ b/lib/elixir/test/elixir/code_formatter/containers_test.exs @@ -200,6 +200,8 @@ defmodule Code.Formatter.ContainersTest do test "with quoted keyword lists" do assert_same ~S(["with spaces": 1]) assert_same ~S(["one #{two} three": 1]) + assert_same ~S(["\w": 1, "\\w": 2]) + assert_same ~S(["Elixir.Foo": 1, "Elixir.Bar": 2]) assert_format ~S(["Foo": 1, "Bar": 2]), ~S([Foo: 1, Bar: 2]) end -- cgit v1.2.1