Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #106 from atambo/master
Strings that start with non-word characters should double quote without exclamation mark
  • Loading branch information
tenderlove committed Dec 9, 2012
2 parents b3609ae + 086fe08 commit d5757ea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/psych/visitors/yaml_tree.rb
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions test/psych/test_yaml.rb
Expand Up @@ -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.