Skip to content

Code.string_to_quoted/2 static_atoms_encoder is not called for quoted keys #11312

@sabiwara

Description

@sabiwara

Environment

  • Elixir & Erlang/OTP versions (elixir --version): Elixir 1.12.1 (compiled with Erlang/OTP 24) (reproduced on master)
  • Operating system: Ubuntu 18.04

Current behavior

iex> Code.string_to_quoted(~S(["foo bar": :baz]), static_atoms_encoder: fn x, _ -> {:ok, x} end)
{:ok, ["foo bar": "baz"]}

The :"foo bar" atom actually gets created. If adding existing_atoms_only, it fails:

iex> Code.string_to_quoted(~S(["foo bar 2": :baz]), static_atoms_encoder: fn x, _ -> {:ok, x} end, existing_atoms_only: true)
** (ArgumentError) errors were found at the given arguments:

  * 1st argument: invalid UTF8 encoding

    :erlang.binary_to_existing_atom("foo bar 2", :utf8)

Expected behavior

The encoder should be called on all static atoms and prevent atom leaks:

iex> Code.string_to_quoted(~S(["foo bar": :baz]), static_atoms_encoder: fn x, _ -> {:ok, x} end)
{:ok, [{"foo bar", "baz"}]}

Note: I have a working fix, will open a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions