Skip to content

Commit 6425a23

Browse files
authored
Revert "Revert "Double quote stings that contain single quotes only""
1 parent 36e6539 commit 6425a23

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

lib/psych/visitors/yaml_tree.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def visit_String o
304304
quote = false
305305
elsif @line_width && o.length > @line_width
306306
style = Nodes::Scalar::FOLDED
307-
elsif o =~ /^[^[:word:]][^"]*$/
307+
elsif o =~ /^[^[:word:]][^"]*$/ or o =~ /^([^"]*'+[^"]*)+$/
308308
style = Nodes::Scalar::DOUBLE_QUOTED
309309
elsif not String === @ss.tokenize(o) or /\A0[0-7]*[89]/ =~ o
310310
style = Nodes::Scalar::SINGLE_QUOTED

test/psych/test_string.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ def test_doublequotes_when_there_is_a_single
3737
assert_equal str, Psych.load(yaml)
3838
end
3939

40+
def test_doublequotes_when_there_are_single_quotes_only
41+
str = "psych: Please don't escape ' with ' here."
42+
yaml = Psych.dump str
43+
assert_equal "--- \"psych: Please don't escape ' with ' here.\"\n", yaml
44+
assert_equal str, Psych.load(yaml)
45+
end
46+
4047
def test_plain_when_shorten_than_line_width_and_no_final_line_break
4148
str = "Lorem ipsum"
4249
yaml = Psych.dump str, line_width: 12

0 commit comments

Comments
 (0)