-
Notifications
You must be signed in to change notification settings - Fork 28
Open
Description
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 withString.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 == result2false
Metadata
Metadata
Assignees
Labels
No labels