Bug #9300
closed
YAML Regression Concerning Escaping of Strings
Added by schneems (Richard Schneeman) almost 11 years ago.
Updated almost 11 years ago.
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
- Assignee set to tenderlovemaking (Aaron Patterson)
- Target version changed from 2.1.0 to 2.2.0
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.
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?
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 :)
- 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
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/
- 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
- 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
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0