Keys starting with capitals are not transformed as described in documentation

未关闭
#44 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
elixir
领域
data

调研方向

未指定源文件或测试。首先针对 decoder 的键处理实现运行 Livebook reproduction,然后查找现有的 atom 键测试。当使用 keys: :atoms 转换的大写键与 String.to_atom/1 的行为一致,并且有一个覆盖 ID 的回归测试时,即视为完成。

由索引模型根据 Issue 内容生成。

描述

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
主要语言
Elixir
星标
206
派生
33
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

bitwalker/toml-elixir 的其他 Issue

查看 bitwalker/toml-elixir 的全部 Issue

相似的 Issue

更多 Elixir Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。