Skip to content

Commit

Permalink
* ext/psych/lib/psych/visitors/yaml_tree.rb: use double quotes when
Browse files Browse the repository at this point in the history
  strings start with special characters.
  [Fixes GH-157] #157

* test/psych/test_string.rb: test for change.

Fixes #157
  • Loading branch information
tenderlove committed Sep 5, 2013
1 parent 02f0498 commit 684612c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.rdoc
@@ -1,3 +1,11 @@
Fri Sep 6 02:37:22 2013 Aaron Patterson <aaron@tenderlovemaking.com>

* ext/psych/lib/psych/visitors/yaml_tree.rb: use double quotes when
strings start with special characters.
[Fixes GH-157] https://github.com/tenderlove/psych/issues/157

* test/psych/test_string.rb: test for change.

Thu Aug 29 02:40:45 2013 Aaron Patterson <aaron@tenderlovemaking.com>

* ext/psych/lib/psych/scalar_scanner.rb: invalid floats should be
Expand Down
2 changes: 2 additions & 0 deletions lib/psych/visitors/yaml_tree.rb
Expand Up @@ -288,6 +288,8 @@ def visit_String o
quote = false
elsif o =~ /\n/
style = Nodes::Scalar::LITERAL
elsif o =~ /^\W/
style = Nodes::Scalar::DOUBLE_QUOTED
else
unless String === @ss.tokenize(o)
style = Nodes::Scalar::SINGLE_QUOTED
Expand Down
5 changes: 5 additions & 0 deletions test/psych/test_string.rb
Expand Up @@ -15,6 +15,11 @@ def initialize
end
end

def test_doublequotes_when_there_is_a_single
yaml = Psych.dump "@123'abc"
assert_match(/---\s*"/, yaml)
end

def test_dash_dot
assert_cycle '-.'
assert_cycle '+.'
Expand Down

0 comments on commit 684612c

Please sign in to comment.