8000 * ext/psych/lib/psych/visitors/yaml_tree.rb: use double quotes when · ruby/ruby@8579a33 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8579a33

Browse files
committed
* ext/psych/lib/psych/visitors/yaml_tree.rb: use double quotes when
strings start with special characters. [Fixes GH-157] ruby/psych#157 * test/psych/test_string.rb: test for change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42850 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent a9ab136 commit 8579a33

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
Fri Sep 6 02:37:22 2013 Aaron Patterson <aaron@tenderlovemaking.com>
2+
3+
* ext/psych/lib/psych/visitors/yaml_tree.rb: use double quotes when
4+
strings start with special characters.
5+
[Fixes GH-157] https://github.com/tenderlove/psych/issues/157
6+
7+
* test/psych/test_string.rb: test for change.
8+
19
Fri Sep 6 00:05:14 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
210

311
* class.c (rewrite_cref_stack): remove recursion.

ext/psych/lib/psych/visitors/yaml_tree.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ def visit_String o
288288
quote = false
289289
elsif o =~ /\n/
290290
style = Nodes::Scalar::LITERAL
291+
elsif o =~ /^\W/
292+
style = Nodes::Scalar::DOUBLE_QUOTED
291293
else
292294
unless String === @ss.tokenize(o)
293295
style = Nodes::Scalar::SINGLE_QUOTED

test/psych/test_string.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ def initialize
1515
end
1616
end
1717

18+
def test_doublequotes_when_there_is_a_single
19+
yaml = Psych.dump "@123'abc"
20+
assert_match(/---\s*"/, yaml)
21+
end
22+
1823
def test_dash_dot
1924
assert_cycle '-.'
2025
assert_cycle '+.'

0 commit comments

Comments
 (0)
0