Bug #9300
closedYAML Regression Concerning Escaping of Strings
Description
=begin
When you run this code against Ruby 2.1.0 and previous versions you get different results:
require 'YAML'
yaml1 = {"key" => %Q{<%= ENV["PATH"] %>} }.to_yaml
puts yaml1
Ruby 2.1.0 incorrectly escapes the quote
key: "<%= ENV["PATH"] %>"
While previous versions do not. Here is my original document for debugging this issue:
https://gist.github.com/schneems/8127922
=end
Updated by hsbt (Hiroshi SHIBATA) almost 11 years ago
- Assignee set to tenderlovemaking (Aaron Patterson)
- Target version changed from 2.1.0 to 2.2.0
Updated by Anonymous almost 11 years ago
It seems legit to me:
>> YAML.load(YAML.dump({"key"=>%{<%= ENV["HOME"] %>}}))
=> {"key"=>"<%= ENV[\"HOME\"] %>"}
Psych is correctly round-tripping the data, so I don't think there's any incorrect escaping happening here.
Updated by Eregon (Benoit Daloze) almost 11 years ago
It should as well round-trip data across versions, which it seems it does in this case.
Yet, I find it worrying quoting is changed in a minor version, should not the YAML spec be clear about this?
Updated by zzak (zzak _) almost 11 years ago
It seems Richard fixed this in Rails master: https://github.com/rails/rails/commit/d0926d3
Should this be closed then? There is a workaround solution available
Updated by schneems (Richard Schneeman) almost 11 years ago
Do we know what changed in psych to cause this? Was this the result of a bug before that was fixed? It is fixed on that Rails commit, but it looks like this is not a stable interface if it can break at any time. I expect to_yaml
to know more about writing valid YAML than me :)
Updated by tenderlovemaking (Aaron Patterson) almost 11 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r44531.
Richard, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
-
ext/psych/lib/psych/visitors/yaml_tree.rb: dumping strings with
quotes should not have changed. [ruby-core:59316] [Bug #9300] -
ext/psych/lib/psych.rb: fixed missing require.
-
test/psych/test_string.rb: test
Updated by tenderlovemaking (Aaron Patterson) almost 11 years ago
On Sat, Dec 28, 2013 at 01:35:02AM +0900, schneems (Richard Schneeman) wrote:
Issue #9300 has been updated by schneems (Richard Schneeman).
Do we know what changed in psych to cause this? Was this the result of a bug before that was fixed? It is fixed on that Rails commit, but it looks like this is not a stable interface if it can break at any time. I expect
to_yaml
to know more about writing valid YAML than me :)
The bug started in r42850. The output is valid YAML and does represent
the same data as it used to. It may look different, but the data is the
same. Though, I see this is trying to write valid ERb via YAML dump.
;-)
The output shouldn't have changed for this, and I fixed it in r44531.
I'll make a request for a backport.
Thanks for reporting this!¶
Aaron Patterson
http://tenderlovemaking.com/
Updated by usa (Usaku NAKAMURA) almost 11 years ago
- Backport changed from 1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: UNKNOWN to 1.9.3: DONTNEED, 2.0.0: DONTNEED, 2.1: REQUIRED
Updated by naruse (Yui NARUSE) almost 11 years ago
- Backport changed from 1.9.3: DONTNEED, 2.0.0: DONTNEED, 2.1: REQUIRED to 1.9.3: DONTNEED, 2.0.0: DONTNEED, 2.1: DONE
r45079.