Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double quote stings that contain single quotes only #325

Merged
merged 1 commit into from
Sep 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/psych/visitors/yaml_tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def visit_String o
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
Expand Down
7 changes: 7 additions & 0 deletions test/psych/test_string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ def test_doublequotes_when_there_is_a_single
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
Expand Down