diff --git a/lib/psych/scalar_scanner.rb b/lib/psych/scalar_scanner.rb index cea2a453..ee13f76c 100644 --- a/lib/psych/scalar_scanner.rb +++ b/lib/psych/scalar_scanner.rb @@ -41,9 +41,9 @@ def tokenize string string elsif string == '~' || string.match?(/^null$/i) nil - elsif string.match?(/^(yes|true|on)$/i) + elsif string.match?(/^(y|yes|true|on)$/i) true - elsif string.match?(/^(no|false|off)$/i) + elsif string.match?(/^(n|no|false|off)$/i) false else string diff --git a/test/psych/test_boolean.rb b/test/psych/test_boolean.rb index a4b80fc1..f16de091 100644 --- a/test/psych/test_boolean.rb +++ b/test/psych/test_boolean.rb @@ -6,32 +6,44 @@ module Psych # Test booleans from YAML spec: # http://yaml.org/type/bool.html class TestBoolean < TestCase - %w{ yes Yes YES true True TRUE on On ON }.each do |truth| + %w{ y Y yes Yes YES true True TRUE on On ON }.each do |truth| define_method(:"test_#{truth}") do assert_equal true, Psych.load("--- #{truth}") end end - %w{ no No NO false False FALSE off Off OFF }.each do |truth| + %w{ n N no No NO false False FALSE off Off OFF }.each do |truth| define_method(:"test_#{truth}") do assert_equal false, Psych.load("--- #{truth}") end end ### - # YAML spec says "y" and "Y" may be used as true, but Syck treats them - # as literal strings - def test_y - assert_equal "y", Psych.load("--- y") - assert_equal "Y", Psych.load("--- Y") + # A quoted 'y' string should load as a string (not +true+). + # A 'y' string should dump a quoted string (not +true+). + # A non-quoted +y+ should load/dump as +true+. + # + # This is incompatible with Ruby's original Syck library, + # but compatible with YAML spec v1.1. + def test_y_str + assert_equal "y", Psych.load("--- 'y'") + assert_equal "Y", Psych.load("--- 'Y'") + assert_equal "--- 'y'\n", Psych.dump('y') + assert_equal "--- 'Y'\n", Psych.dump('Y') end ### - # YAML spec says "n" and "N" may be used as false, but Syck treats them - # as literal strings - def test_n - assert_equal "n", Psych.load("--- n") - assert_equal "N", Psych.load("--- N") + # A quoted 'n' string should load as a string (not +false+). + # An 'n' string should dump a quoted string (not +false+). + # A non-quoted +n+ should load/dump as +false+. + # + # This is incompatible with Ruby's original Syck library, + # but compatible with YAML spec v1.1. + def test_n_str + assert_equal "n", Psych.load("--- 'n'") + assert_equal "N", Psych.load("--- 'N'") + assert_equal "--- 'n'\n", Psych.dump('n') + assert_equal "--- 'N'\n", Psych.dump('N') end end end diff --git a/test/psych/test_merge_keys.rb b/test/psych/test_merge_keys.rb index 1bc3dd1c..a3ae8370 100644 --- a/test/psych/test_merge_keys.rb +++ b/test/psych/test_merge_keys.rb @@ -130,8 +130,8 @@ def test_merge_key def test_multiple_maps yaml = <<-eoyaml --- -- &CENTER { x: 1, y: 2 } -- &LEFT { x: 0, y: 2 } +- &CENTER { x: 1, 'y': 2 } +- &LEFT { x: 0, 'y': 2 } - &BIG { r: 10 } - &SMALL { r: 1 } @@ -155,8 +155,8 @@ def test_multiple_maps def test_override yaml = <<-eoyaml --- -- &CENTER { x: 1, y: 2 } -- &LEFT { x: 0, y: 2 } +- &CENTER { x: 1, 'y': 2 } +- &LEFT { x: 0, 'y': 2 } - &BIG { r: 10 } - &SMALL { r: 1 } diff --git a/test/psych/test_yaml.rb b/test/psych/test_yaml.rb index 5fa759c9..78d75d87 100644 --- a/test/psych/test_yaml.rb +++ b/test/psych/test_yaml.rb @@ -751,11 +751,11 @@ def test_spec_application_family [[{"radius"=>7, "center"=>{"x"=>73, "y"=>129}, "TYPE"=>"Shape: graph/circle"}, {"finish"=>{"x"=>89, "y"=>102}, "TYPE"=>"Shape: graph/line", "start"=>{"x"=>73, "y"=>129}}, {"TYPE"=>"Shape: graph/text", "value"=>"Pretty vector drawing.", "start"=>{"x"=>73, "y"=>129}, "color"=>16772795}, "Shape Container"]], <