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

Already on GitHub? Sign in to your account

Double quotes #157

Closed
Exoth opened this Issue Sep 2, 2013 · 2 comments

Comments

2 participants

Exoth commented Sep 2, 2013

Pull request #106 makes this:

Psych.dump("@123'abc")
--- "@123'abc"

But now it's again back to single quotes because of this commit: 69a1aea

It would be great if double quotes are used in case a single quote is inside the dumped string and there are no double quotes inside.

@tenderlove tenderlove closed this in 684612c Sep 5, 2013

Exoth commented Sep 6, 2013

As I said, it woulde be better to put double quotes only in case a single quote is inside the dumped string and there are no double quotes inside.

So before the fix:

Psych.dump("@123'abc")
--- '@123''abc'

After the fix:

Psych.dump("@123'abc")
--- "@123'abc"

This one works great. But here's another case before the fix:

Psych.dump('@123"abc')
--- '@123"abc'

And after the fix:

Psych.dump('@123"abc')
--- "@123\"abc"

Well, this one looked better before the fix.

So the regexp for double quotes should be like /^\W[^"]*$/ or something with the similar effect. Not sure though if it's going to make some performance decline.

headius pushed a commit to headius/ruby that referenced this issue Oct 31, 2013

* ext/psych/lib/psych/visitors/yaml_tree.rb: use double quotes when
  strings start with special characters.
  [Fixes GH-157] ruby/psych#157

* test/psych/test_string.rb: test for change.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42850 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

tenderlove added a commit to tenderlove/ruby that referenced this issue Jan 24, 2014

* ext/psych/lib/psych/visitors/yaml_tree.rb: use double quotes when
  strings start with special characters.
  [Fixes GH-157] ruby/psych#157

* test/psych/test_string.rb: test for change.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42850 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

wteuber commented Jul 18, 2017 edited

@tenderlove I found the same issue when there is a key involved. Especially when working with i18n's YAML files this is confusing people.

Psych.dump("key: @123'abc")
--- 'key: @123''abc'

Do you agree that's worth fixing as well?
Thanks a lot in advanced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment