diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-12-08 16:25:26 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-12-08 16:25:26 -0800 |
commit | d5757eaddab8aae701d8ab30c6d8d420e54db535 (patch) | |
tree | 668d4539d45cad576bd1853ae3fadd4f39c11270 | |
parent | b3609ae8edeea80c0eda4d406011f740fb639cf2 (diff) | |
parent | 086fe0853135acdcfc768e339c9791a883b5c325 (diff) | |
download | psych-d5757eaddab8aae701d8ab30c6d8d420e54db535.tar.gz |
Merge pull request #106 from atambo/master
Strings that start with non-word characters should double quote without exclamation mark
-rw-r--r-- | lib/psych/visitors/yaml_tree.rb | 3 | ||||
-rw-r--r-- | test/psych/test_yaml.rb | 6 |
2 files changed, 9 insertions, 0 deletions
diff --git a/lib/psych/visitors/yaml_tree.rb b/lib/psych/visitors/yaml_tree.rb index d420abd..5efb654 100644 --- a/lib/psych/visitors/yaml_tree.rb +++ b/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 cbda385..5e1ebb4 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 |