Bug #10824
closedto_yaml incorrectly inserts return lines
Description
"{\"config_path\":\"something\",\"mode\":\"something_underscore\",\"person\":{\"id\":1,\"name\":\"Christopher Michael Thielen\",\"address\":\"First Shields Ave\"}}".to_yaml
returns:
"--- '{\"config_path\":\"something\",\"mode\":\"something_underscore\",\"person\":{\"id\":1,\"name\":\"Christopher\n Michael Thielen\",\"address\":\"First Shields Ave\"}}'\n"
Note that a newline has been inserted after the word ‘Christopher’. It shouldn’t be there.
Curiously enough, if we leave out, say, the “mode” key, the newline shifts around:
"{\"config_path\":\"something\",\"person\":{\"id\":1,\"name\":\"Christopher Michael Thielen\",\"address\":\"First Shields Ave\"}}".to_yaml
returns:
"--- '{\"config_path\":\"something\",\"person\":{\"id\":1,\"name\":\"Christopher Michael Thielen\",\"address\":\"First\n Shields Ave\"}}'\n"
Note that the newline isn’t after ‘Christopher' anymore but is after the word ‘First’.
This functionality appears in at least:
ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-darwin12.5.0]
and
ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-darwin14.0]
Updated by nobu (Nobuyoshi Nakada) about 9 years ago
- Assignee set to tenderlovemaking (Aaron Patterson)
- Description updated (diff)
- Status changed from Open to Assigned
Maybe a word wrapping?
Updated by tenderlovemaking (Aaron Patterson) about 9 years ago
I don't understand. Why should it not insert the newline? The string will roundtrip correctly:
>> require 'yaml'
=> true
>> s = "{\"config_path\":\"something\",\"mode\":\"something_underscore\",\"person\":{\"id\":1,\"name\":\"Christopher Michael Thielen\",\"address\":\"First Shields Ave\"}}"
=> "{\"config_path\":\"something\",\"mode\":\"something_underscore\",\"person\":{\"id\":1,\"name\":\"Christopher Michael Thielen\",\"address\":\"First Shields Ave\"}}"
>> s == YAML.load(s.to_yaml)
=> true
>>
I think I can add an option for the width of the yaml produced, but I don't think this is a bug.
Updated by cthielen (Christopher Thielen) about 9 years ago
You're right.
I saw the newlines in my database and filed the bug but they do disappear when de-serializing, so this is not a bug.
Thanks for clearing that up.
Out of curiosity, why does it insert newlines at all? Does it have to do with YAML's readability?
Updated by jeremyevans0 (Jeremy Evans) over 4 years ago
- Status changed from Assigned to Closed