YAML.dump inconsistent handling of nil values

Viewed 88

I'm tired of trying to debug this, hope someone can jump in and help me to find solution.

We are using YAML.dump function to create state capture in our tests. Found strange diff conflicts after moving from docker to Mac Os Catalina local versions. The difference we notice is in the way how nil keys are being dumped. On linux nil values are being replaced with empty space. While on my mac for some reason nil values are being swallowed by YAML.dump completely without any traces.

Expected Result

In Docker and Linux:

RUBY_VERSION
=> "2.3.8"
require 'yaml'; YAML.dump({user_name: "Maxim", start_time: nil, end_time: nil})
=> "---\n:user_name: Maxim\n:start_time: \n:end_time: \n"

On Mac(using built-in ruby)

RUBY_VERSION
=> "2.6.3"
irb(main):004:0> require 'yaml'; YAML.dump({user_name: "Maxim", start_time: nil, end_time: nil})
=> "---\n:user_name: Maxim\n:start_time: \n:end_time: \n"

Actual result from ruby versions compiled with ruby-build

On Mac(2.3.8, 2.4.0, 2.6.3, 2.7.2) Tried to install via asdf(uses ruby-build) and rbenv the same results

irb(main):002:0> require 'yaml'; YAML.dump({user_name: "Maxim", start_time: nil, end_time: nil})
=> "---\n:user_name: Maxim\n:start_time:\n:end_time:\n"

It seem that the problem is related to ruby-build as linux uses pre-compiled version. Could be related somehow to changes in xcode?

System details

  • Xcode-version Version 12.3 (12C33)
  • ruby-build 20201210
  • mac os 10.15.7 (19H15)
0 Answers
Related