`nil` value in Hash generates trailing whitespace
abitrolly opened this issue · 6 comments
abitrolly commented
3.1.2 :015 > h = {"xxx": "111", "yyy": nil}
=> {:xxx=>"111", :yyy=>nil}
3.1.2 :016 > h.to_yaml
=> "---\n:xxx: '111'\n:yyy: \n"
3.1.2 :017 > j = {"xxx": "111", "yyy": ""}
=> {:xxx=>"111", :yyy=>""}
3.1.2 :018 > j.to_yaml
=> "---\n:xxx: '111'\n:yyy: ''\n"
This makes yamllint
fail as in #591.
hsbt commented
We don't support yamllint
, only yaml spec.
abitrolly commented
@hsbt I am not familiar with the yaml spec enough. Does it direct to produce trailing whitespace on null values?
perlpunk commented
The spec doesn't say anything about whitespace in this regard.
But a YAML emitter ideally should avoid producing such trailing whitespace.
libyaml had the same problem and I fixed it two years ago, so maybe this can help:
yaml/libyaml#186
nobu commented
I think it depends on the version of libyaml, not psych.
$ ruby3.1 -v -rpsych -e 'p({"xxx": "111", "yyy": nil}.to_yaml)'
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-darwin21]
"---\n:xxx: '111'\n:yyy:\n"
Since libyaml on Ubuntu is old, the result package differs from files generated on macOS/Windows.