Skip to content

Keys starting with capitals are not transformed as described in documentation #44

@pichi

Description

@pichi

The issue can be demonstrated by following Livebook (see source for copy):

TOML atoms issue

Mix.install([
  {:toml, "~> 0.7.0"}
])

Section

According to the documentation:

You can pass the following options to configure the decoder behavior:

:keys - controls how keys in the document are decoded. Possible values are:

     :atoms - converts keys to atoms with String.to_atom/1

So in my opinion, it should be equivalent to keys: &String.to_atom/1

toml_content = """
[foo]
name = "bar"
ID = "baz"
"""

result1 = Toml.decode!(toml_content, keys: :atoms)
%{foo: %{:name => "bar", ID => "baz"}}

Note the map key is ID, which means atom :"Elixir.ID". But when I use String.to_atom/1:

result2 = Toml.decode!(toml_content, keys: &String.to_atom/1)
%{foo: %{name: "bar", ID: "baz"}}

Note ID:, which means the key is atom :"ID". This behaviour is what I would expect after reading the documentation. The results are not equivalent, obviously.

result1 == result2
false

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions