diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | ext/psych/lib/psych/visitors/yaml_tree.rb | 3 | ||||
-rw-r--r-- | test/psych/test_yaml.rb | 6 |
3 files changed, 15 insertions, 0 deletions
@@ -1,3 +1,9 @@ +Fri Dec 14 07:43:44 2012 Aaron Patterson <aaron@tenderlovemaking.com> + + * ext/psych/lib/psych/visitors/yaml_tree.rb: quote strings that begin + with non-word characters. Thanks Alex Tambellini! + * test/psych/test_yaml.rb: appropriate test case + Thu Dec 13 23:14:17 2012 Shugo Maeda <shugo@ruby-lang.org> * vm_insnhelper.c (vm_call_super_method): a workaround for the diff --git a/ext/psych/lib/psych/visitors/yaml_tree.rb b/ext/psych/lib/psych/visitors/yaml_tree.rb index d420abd64e..5efb654aab 100644 --- a/ext/psych/lib/psych/visitors/yaml_tree.rb +++ b/ext/psych/lib/psych/visitors/yaml_tree.rb @@ -242,6 +242,9 @@ module Psych 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 diff --git a/test/psych/test_yaml.rb b/test/psych/test_yaml.rb index cbda3859e6..5e1ebb4b4b 100644 --- a/test/psych/test_yaml.rb +++ b/test/psych/test_yaml.rb @@ -1271,4 +1271,10 @@ EOY yaml = Psych.dump("multi\nline\nstring") assert_match("|", yaml) end + + 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 end |