Skip to content

Strings that start with non-word characters should double quote without exclamation mark #106

Merged
merged 1 commit into from Dec 9, 2012
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
Something went wrong with that request. Please try again.