File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 /\A 0[0-7]*[89]/ =~ o
310310 style = Nodes ::Scalar ::SINGLE_QUOTED
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments