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
Comments
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: All of the following key words are transformed into booleans: YAML 1.1 specification
YAML 1.2 specification:
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. |
Thanks for the info on the spec.
I think there still might be an issue here because when calling
ext_load_file with the unquoted key 'no' the entry is removed completely.
I'm almost positive when I looked at this last night, the native load does
not strip the entry, but will need to double check on Monday.
…On Sat, Mar 27, 2021, 05:30 Matthäus J. N. Beyrle ***@***.***> wrote:
Hi @patrickberkeley <https://github.com/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.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAACBLCE3EQ5VSSC6R2SLJTTFWQSFANCNFSM4Z4H2R2A>
.
|
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. 👍🏻 |
@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. |
@patrickberkeley this behaviour of YAML was also new to me, to thanks for inspiring me. 👍🏻 |
Please see the failing spec here: #13
The text was updated successfully, but these errors were encountered: