bitwalker / bitwalker/toml-elixir
Keys starting with capitals are not transformed as described in documentation
- Dominant language
- Elixir
- Stars
- 206
- Forks
- 32
- PR merge metrics
- No merged PRs in 30d
Description
The issue can be demonstrated by following Livebook (see source for copy):
# TOML atoms issue
```elixir
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`
```elixir
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`:
```elixir
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.
```elixir
result1 == result2
```
```
false
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.