Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit d5757eaddab8aae701d8ab30c6d8d420e54db535 2 parents b3609ae + 086fe08
@tenderlove authored
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
Please sign in to comment.
Something went wrong with that request. Please try again.