Skip to content

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

Merged
tenderlove merged 1 commit intomasterfrom
quote-y-n
Aug 5, 2021
Merged

Add quotes to the strings "y" and "n"#515
tenderlove merged 1 commit intomasterfrom
quote-y-n

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Quoting strings y/n when dumping?

2 participants