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

Add quotes to the strings "y" and "n" #515

Merged
merged 1 commit into from
Aug 5, 2021
Merged

Add quotes to the strings "y" and "n" #515

merged 1 commit into from
Aug 5, 2021

Conversation

tenderlove
Copy link
Member

'y' and 'n' are kind of ambiguous. Syck treated y and n literals in
YAML documents as strings. But this is not what the YAML 1.1 spec says.
YAML 1.1 says they should be treated as booleans. When we're dumping
documents, we know it's a string, so adding quotes will eliminate the
"ambiguity" in the emitted document

Fixes #443

'y' and 'n' are kind of ambiguous.  Syck treated y and n literals in
YAML documents as strings.  But this is not what the YAML 1.1 spec says.
YAML 1.1 says they should be treated as booleans.  When we're dumping
documents, we know it's a string, so adding quotes will eliminate the
"ambiguity" in the emitted document

Fixes #443
@tenderlove tenderlove merged commit 02f759d into master Aug 5, 2021
@tenderlove tenderlove deleted the quote-y-n branch August 5, 2021 00:10
@ColinDKelley
Copy link
Contributor

@tenderlove It looks like this is still broken for "Y" and "N".

Taken from Regexp given in the Boolean Language-Independent Type for YAML™ Version 1.1:

irb> yaml_1_1_bools = "y|Y|yes|Yes|YES|n|N|no|No|NO
|true|True|TRUE|false|False|FALSE
|on|On|ON|off|Off|OFF".split(/[\s\|]/)
=> ["y", "Y", "yes", "Yes", "YES", "n", "N", "no", "No", "NO", "", "true", "True", "TRUE", "false", "False", "FALSE", "", "on", "On", "ON", "off", "Off", "OFF"]

irb> yaml_1_1_bools.reject { |bool| bool.to_yaml.match?(/['"]/) }
=> ["Y", "N"]

I can make a PR if you like.

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

Successfully merging this pull request may close these issues.

Quoting strings y/n when dumping?
2 participants