diff options
-rw-r--r-- | CHANGELOG.rdoc | 8 | ||||
-rw-r--r-- | lib/psych/visitors/yaml_tree.rb | 2 | ||||
-rw-r--r-- | test/psych/test_string.rb | 5 |
3 files changed, 15 insertions, 0 deletions
diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index d504369..2acf4e5 100644 --- a/CHANGELOG.rdoc +++ b/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 diff --git a/lib/psych/visitors/yaml_tree.rb b/lib/psych/visitors/yaml_tree.rb index eb1f0d7..f8bece6 100644 --- a/lib/psych/visitors/yaml_tree.rb +++ b/lib/psych/visitors/yaml_tree.rb @@ -288,6 +288,8 @@ module Psych 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 diff --git a/test/psych/test_string.rb b/test/psych/test_string.rb index 2512bb6..025ef95 100644 --- a/test/psych/test_string.rb +++ b/test/psych/test_string.rb @@ -15,6 +15,11 @@ module Psych 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 '+.' |