psych icon indicating copy to clipboard operation
psych copied to clipboard

Coord y is being rendered as 'y' but x is still x

Open sramsden opened this issue 2 years ago • 1 comments

I have a rails model with coords, and when dumped to yml the y is rendered incorrectly.

For example,

>> puts Coord.new(x: 13, y: 12).attributes.to_yaml
---
id:
x: 13
"y": 12

instead of the expected

>> puts Coord.new(x: 13, y: 12).attributes.to_yaml
---
id:
x: 13
y: 12

This comes about because of this change ... https://github.com/ruby/psych/commit/6a1c30634e61967f3d8133b3181b9f301ff7f550

I have commented out those lines and I get the expected coord rendered. I'm not sure what the solution is because I know that change was added to appease yes/no boolean guff but unfortunately y is a known coordinate also 🤷

sramsden avatar Apr 07 '22 05:04 sramsden

That commit was the fix for https://github.com/ruby/psych/issues/443.

Can you show, what the result of #attributes is that get's #to_yaml called on?

I'm assuming something like this (which is the correct behaviour IMO):

002 > puts({"x" => "1", "y" => "2"}.to_yaml)
---
x: '1'                                       
"y": '2'                                     
 => nil

I'm not exactly sure what the problem is, @sramsden. Unless you want the key to be interpreted as true (one of the unfortunate YAML spec attributes), then "y": 12 is "y" as a string key.

tisba avatar Sep 09 '22 10:09 tisba