Skip to content

Double quote strings that contain single quotes only (retry)#336

Open
hsbt wants to merge 1 commit into
masterfrom
revert-335-revert-325-fix_324
Open

Double quote strings that contain single quotes only (retry)#336
hsbt wants to merge 1 commit into
masterfrom
revert-335-revert-325-fix_324

Conversation

@hsbt

@hsbt hsbt commented Nov 29, 2017

Copy link
Copy Markdown
Member

Original pull request: #325

@knugie Your changes was different behavior with bundler behavior: https://github.com/bundler/bundler/blob/master/lib/bundler/yaml_serializer.rb#L8

There is no time to coordinate this specification for Ruby 2.5.0. I try to this next year(Ruby 2.6 and psych 3.1.0)

@stomar stomar changed the title Double quote stings that contain single quotes only (retry) Double quote strings that contain single quotes only (retry) Nov 29, 2017
@hsbt hsbt force-pushed the revert-335-revert-325-fix_324 branch from 6425a23 to 8a3710a Compare June 9, 2026 08:15
Copilot AI review requested due to automatic review settings June 9, 2026 08:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts Psych’s YAML string emission to prefer double-quoted scalars for strings that contain single-quote characters (but no double quotes), avoiding the YAML single-quote escaping behavior (''). It adds a regression test to lock in the expected output and round-trip loading.

Changes:

  • Add a new test asserting that strings containing ' are emitted with double quotes (to avoid escaping).
  • Update Psych::Visitors::YAMLTree#visit_String to select Nodes::Scalar::DOUBLE_QUOTED for strings matching the new “single quotes present, no double quotes” condition.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
test/psych/test_string.rb Adds regression coverage for double-quoting strings containing single quotes to avoid escaping.
lib/psych/visitors/yaml_tree.rb Updates string-style selection logic to emit double-quoted scalars for the new case.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +314 to 315
elsif o.match?(/^[^[:word:]][^"]*$/) || o.match?(/^([^"]*'+[^"]*)+$/)
style = Nodes::Scalar::DOUBLE_QUOTED
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants