diff --git a/lib/psych/visitors/yaml_tree.rb b/lib/psych/visitors/yaml_tree.rb index 51491783..c32f115d 100644 --- a/lib/psych/visitors/yaml_tree.rb +++ b/lib/psych/visitors/yaml_tree.rb @@ -272,7 +272,7 @@ def visit_String o tag = 'tag:yaml.org,2002:str' plain = false quote = false - elsif o == 'y' || o == 'n' + elsif o == 'y' || o == 'Y' || o == 'n' || o == 'N' style = Nodes::Scalar::DOUBLE_QUOTED elsif @line_width && o.length > @line_width style = Nodes::Scalar::FOLDED diff --git a/test/psych/test_string.rb b/test/psych/test_string.rb index 0dc34b30..c996a8fc 100644 --- a/test/psych/test_string.rb +++ b/test/psych/test_string.rb @@ -24,10 +24,19 @@ def initialize # "ambiguity" in the emitted document def test_y_is_quoted assert_match(/"y"/, Psych.dump("y")) + assert_match(/"Y"/, Psych.dump("Y")) end def test_n_is_quoted assert_match(/"n"/, Psych.dump("n")) + assert_match(/"N"/, Psych.dump("N")) + end + + def test_all_yaml_1_1_booleans_are_quoted + yaml_1_1_booleans = %w[y Y yes Yes YES n N no No NO true True TRUE false False FALSE on On ON off Off OFF] # from https://yaml.org/type/bool.html + yaml_1_1_booleans.each do |boolean| + assert_match(/"#{boolean}"|'#{boolean}'/, Psych.dump(boolean)) + end end def test_string_with_newline