summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolfgang Teuber <knugie@gmx.net>2017-07-21 08:32:00 +0200
committerWolfgang Teuber <knugie@gmx.net>2017-07-21 08:39:43 +0200
commit803de61352145c2bd3c9237b2253fe931c286f24 (patch)
tree30f83c038549fb652fa82a5706ea87e6075e3be2
parent4039a811248de7b0b9ae9e4a97854f00ba985255 (diff)
downloadpsych-803de61352145c2bd3c9237b2253fe931c286f24.zip
Double quote stings that contain single quotes only
Fixes #324
-rw-r--r--lib/psych/visitors/yaml_tree.rb2
-rw-r--r--test/psych/test_string.rb7
2 files changed, 8 insertions, 1 deletions
diff --git a/lib/psych/visitors/yaml_tree.rb b/lib/psych/visitors/yaml_tree.rb
index cfed8f1..f44e973 100644
--- a/lib/psych/visitors/yaml_tree.rb
+++ b/lib/psych/visitors/yaml_tree.rb
@@ -304,7 +304,7 @@ module Psych
quote = false
elsif @line_width && o.length > @line_width
style = Nodes::Scalar::FOLDED
- elsif o =~ /^[^[:word:]][^"]*$/
+ elsif o =~ /^[^[:word:]][^"]*$/ or o =~ /^([^"]*'+[^"]*)+$/
style = Nodes::Scalar::DOUBLE_QUOTED
elsif not String === @ss.tokenize(o) or /\A0[0-7]*[89]/ =~ o
style = Nodes::Scalar::SINGLE_QUOTED
diff --git a/test/psych/test_string.rb b/test/psych/test_string.rb
index 973f38b..e80d191 100644
--- a/test/psych/test_string.rb
+++ b/test/psych/test_string.rb
@@ -37,6 +37,13 @@ module Psych
assert_equal str, Psych.load(yaml)
end
+ def test_doublequotes_when_there_are_single_quotes_only
+ str = "psych: Please don't escape ' with ' here."
+ yaml = Psych.dump str
+ assert_equal "--- \"psych: Please don't escape ' with ' here.\"\n", yaml
+ assert_equal str, Psych.load(yaml)
+ end
+
def test_plain_when_shorten_than_line_width_and_no_final_line_break
str = "Lorem ipsum"
yaml = Psych.dump str, line_width: 12