Permalink
Browse files

Merge pull request #106 from atambo/master

Strings that start with non-word characters should double quote without exclamation mark
  • Loading branch information...
2 parents b3609ae + 086fe08 commit d5757eaddab8aae701d8ab30c6d8d420e54db535 @tenderlove tenderlove committed Dec 9, 2012
Showing with 9 additions and 0 deletions.
  1. +3 −0 lib/psych/visitors/yaml_tree.rb
  2. +6 −0 test/psych/test_yaml.rb
View
3 lib/psych/visitors/yaml_tree.rb
@@ -242,6 +242,9 @@ def visit_String o
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
View
6 test/psych/test_yaml.rb
@@ -1271,4 +1271,10 @@ def test_multiline_string_uses_literal_style
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

0 comments on commit d5757ea

Please sign in to comment.