This project is archived and is in readonly mode.
ActiveSupport::JSON fails to decode unicode-escaped newline and literal newlines
-
Ethan
formatting seems to have gotten lost; that last line was supposed to say:
change "\n" to "\\n"; change "\r\n" to "\\r\\n", as YAML correctly converts those to literal newlines.(maybe it will work this time? where's the preview function on this thing?)
-
Maxime RETY
- Tag changed from activesupport, decode, json, newline, yaml to activesupport, decode, json, newline, patch, yaml
As you previously reported it, ActiveSupport::JSON fails to decode a unicode-escaped newline with the YAML backend :
unicode-escaped LF
ActiveSupport::JSON.decode(""\u000a"") => " "
With the new Yajl backend, same code works :
unicode-escaped LF (with Yajl backend)
ActiveSupport::JSON.decode(""\u000a"") => "\n"
I did not test with JSON gem, since it's not a default json backend since rails 2.3.6.
I believe "\n" char is interpreted in YAML as a formatting instruction of the file.
So newlines need to be escaped as "\n" before passing yaml string to "YAML.load" method.I also think it's a newline-only bug. Other "backslash-chars" like "\r" are correctly handled without extra escaping.
I propose the attached patch to fix the issue in "convert_json_to_yaml" method.
I added 3 tests to check that bug is fixed with any backend.Did you have any other feedback on this issue ?
-
Maxime RETY
Oops i should have read formatting help more carefully !
As you previously reported it, ActiveSupport::JSON fails to decode a unicode-escaped newline with the YAML backend :
# unicode-escaped LF
ActiveSupport::JSON.decode("\"\\u000a\"")
=> " "With the new Yajl backend, same code works :
# unicode-escaped LF (with Yajl backend)
ActiveSupport::JSON.decode("\"\\u000a\"")
=> "\n"I did not test with JSON gem, since it's not a default json backend since rails 2.3.6.
I believe "\n" char is interpreted in YAML as a formatting instruction of the file.
So newlines need to be escaped as "\\n" before passing yaml string to "YAML.load" method.I propose the attached patch to fix the issue in "convert_json_to_yaml" method.
I added 3 tests to check that bug is fixed with any backend.Did you have any other feedback on this issue ?
-
Michael Koziarski
- Milestone set to 2.3.9
-
Santiago Pastorino
- State changed from new to open
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
Santiago Pastorino
- State changed from open to stale
-
Ethan
- State changed from stale to open
This is still reproducing in ActiveSupport 3.0.3. Maxime's patch should be applied.
[state:open]
-
Repository
- State changed from open to resolved
(from [68e3fb81090ba67575e513407fc2463dba3b002b]) Fix JSON decoding of newline character with Yaml backend [#3479 state:resolved]
Signed-off-by: Santiago Pastorino santiago@wyeworks.com
https://github.com/rails/rails/commit/68e3fb81090ba67575e513407fc24...
