Permalink
Browse files

* ext/psych/lib/psych/visitors/yaml_tree.rb: fixing string quotation

  when dumping Ruby strings. Thanks Ingy

* test/psych/test_psych.rb: appropriate tests.

* test/psych/test_yaml.rb: ditto
  • Loading branch information...
1 parent 4ed9ce4 commit 69a1aea11b5687a500d0901e7513691766ce80d4 @tenderlove tenderlove committed Feb 7, 2013
Showing with 28 additions and 11 deletions.
  1. +9 −0 CHANGELOG.rdoc
  2. +8 −9 lib/psych/visitors/yaml_tree.rb
  3. +1 −1 test/psych/test_psych.rb
  4. +10 −1 test/psych/test_yaml.rb
View
@@ -1,3 +1,12 @@
+Fri Feb 8 08:53:27 2013 Aaron Patterson <aaron@tenderlovemaking.com>
+
+ * ext/psych/lib/psych/visitors/yaml_tree.rb: fixing string quotation
+ when dumping Ruby strings. Thanks Ingy
+
+ * test/psych/test_psych.rb: appropriate tests.
+
+ * test/psych/test_yaml.rb: ditto
+
Fri Feb 8 08:50:42 2013 Aaron Patterson <aaron@tenderlovemaking.com>
* ext/psych/lib/psych/visitors/yaml_tree.rb: change output reference
@@ -253,9 +253,9 @@ def binary? string
private :binary?
def visit_String o
- plain = false
- quote = false
- style = Nodes::Scalar::ANY
+ plain = true
+ quote = true
+ style = Nodes::Scalar::PLAIN
tag = nil
str = o
@@ -264,15 +264,14 @@ def visit_String o
tag = '!binary' # FIXME: change to below when syck is removed
#tag = 'tag:yaml.org,2002:binary'
style = Nodes::Scalar::LITERAL
+ plain = false
+ quote = false
elsif o =~ /\n/
- quote = true
style = Nodes::Scalar::LITERAL
- elsif o =~ /^\W/
- quote = true
- style = Nodes::Scalar::DOUBLE_QUOTED
else
- quote = !(String === @ss.tokenize(o))
- plain = !quote
+ unless String === @ss.tokenize(o)
+ style = Nodes::Scalar::SINGLE_QUOTED
+ end
end
ivars = find_ivars o
View
@@ -20,7 +20,7 @@ def test_indent
def test_canonical
yml = Psych.dump({:a => {'b' => 'c'}}, {:canonical => true})
- assert_match(/\? ! "b/, yml)
+ assert_match(/\? "b/, yml)
end
def test_header
View
@@ -1274,7 +1274,16 @@ def test_multiline_string_uses_literal_style
def test_string_starting_with_non_word_character_uses_double_quotes_without_exclamation_mark
yaml = Psych.dump("@123'abc")
- assert_match("\"", yaml)
refute_match("!", yaml)
end
+
+ def test_string_dump_with_colon
+ yaml = Psych.dump 'x: foo'
+ refute_match '!', yaml
+ end
+
+ def test_string_dump_starting_with_star
+ yaml = Psych.dump '*foo'
+ refute_match '!', yaml
+ end
end

0 comments on commit 69a1aea

Please sign in to comment.