Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ext_load_file mutates/removes some falsey keys #14

Closed
patrickberkeley opened this issue Mar 26, 2021 · 5 comments
Closed

ext_load_file mutates/removes some falsey keys #14

patrickberkeley opened this issue Mar 26, 2021 · 5 comments

Comments

@patrickberkeley
Copy link

Please see the failing spec here: #13

@magynhard
Copy link
Owner

Hi @patrickberkeley,

thank you for your contribution.

At first I thought, that there may be a bug, but the YAML library itself has the same behaviour, so it happend not by my extending gem.

After some research I found out, that your described behaviour is indeed a part of the official YAML specification:
https://yaml.org/type/bool.html

All of the following key words are transformed into booleans:

YAML 1.1 specification

 y|Y|yes|Yes|YES|n|N|no|No|NO
|true|True|TRUE|false|False|FALSE
|on|On|ON|off|Off|OFF

YAML 1.2 specification:

true | True | TRUE | false | False | FALSE

Ruby YAML apparently implements the 1.1 specification.

If you want to use keys or values with these key words not to be transformed into their boolean values, you have to quote them.

@patrickberkeley
Copy link
Author

patrickberkeley commented Mar 27, 2021 via email

@magynhard
Copy link
Owner

I just tried an simple example in IRB:

require 'yaml'
require 'yaml_extend'

YAML.load 'no: so'
# => {false=>"so"} 

File.write "t.yml","no: so"
# => 6

YAML.load_file "t.yml"
# => {false=>"so"} 

YAML.ext_load_file "t.yml"
# => {false=>"so"}

I did not recognize your description, but maybe you have another constellation where a error may happen. Even a simple sample with inheritance worked fine.

You are invited to give an example that does not work in your case, then i will see what I can do for you. 👍🏻

@patrickberkeley
Copy link
Author

@magynhard you are correct. The issue I'm seeing is if I have multiple keys that are evaluated as false, the last one wins and the previous ones don't appear in the output e.g.,

require 'yaml'

YAML.load '{ no: "no", false: "false" }'
# => {false=>"false"} 

YAML.load '{ false: "false", no: "no" }'
# => {false=>"no"} 

This is normal behavior, but the whole yaml-changing-keys thing is new to me.

@magynhard
Copy link
Owner

@patrickberkeley this behaviour of YAML was also new to me, to thanks for inspiring me. 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants