diff options
author | Alex Tambellini <atambellini@gmail.com> | 2012-12-08 15:00:02 -0500 |
---|---|---|
committer | Alex Tambellini <atambellini@gmail.com> | 2012-12-08 19:02:10 -0500 |
commit | 086fe0853135acdcfc768e339c9791a883b5c325 (patch) | |
tree | 668d4539d45cad576bd1853ae3fadd4f39c11270 | |
parent | b3609ae8edeea80c0eda4d406011f740fb639cf2 (diff) | |
download | psych-086fe0853135acdcfc768e339c9791a883b5c325.zip |
Strings that start with non-word characters should double quote without exclamation mark
Before this commit:
--- ! '@123''abc'
After this commit:
--- "@123'abc"
-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 |