ruby-changes:15217
From: tenderlove <ko1@a...>
Date: Tue, 30 Mar 2010 08:57:52 +0900 (JST)
Subject: [ruby-changes:15217] Ruby:r27099 (trunk): * lib/psych.rb: Fix problem with empty and white-space only strings.
tenderlove 2010-03-30 08:57:25 +0900 (Tue, 30 Mar 2010) New Revision: 27099 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=27099 Log: * lib/psych.rb: Fix problem with empty and white-space only strings. Thanks Peter McLain! * test/psych/test_psych.rb: tests for change. Modified files: trunk/ChangeLog trunk/lib/psych.rb trunk/test/psych/test_psych.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 27098) +++ ChangeLog (revision 27099) @@ -1,3 +1,9 @@ +Tue Mar 30 08:10:59 2010 Aaron Patterson <aaron@t...> + + * lib/psych.rb: Fix problem with empty and white-space only strings. + Thanks Peter McLain! + * test/psych/test_psych.rb: tests for change. + Tue Mar 30 05:31:39 2010 Aaron Patterson <aaron@t...> * lib/psych.rb: documentation updates. Thanks Peter McLain! Index: lib/psych.rb =================================================================== --- lib/psych.rb (revision 27098) +++ lib/psych.rb (revision 27099) @@ -101,7 +101,8 @@ # Psych.load("--- a") # => 'a' # Psych.load("---\n - a\n - b") # => ['a', 'b'] def self.load yaml - parse(yaml).to_ruby + result = parse(yaml) + result ? result.to_ruby : result end ### @@ -113,7 +114,8 @@ # # See Psych::Nodes for more information about YAML AST. def self.parse yaml - parse_stream(yaml).children.first.children.first + children = parse_stream(yaml).children + children.empty? ? false : children.first.children.first end ### Index: test/psych/test_psych.rb =================================================================== --- test/psych/test_psych.rb (revision 27098) +++ test/psych/test_psych.rb (revision 27099) @@ -66,4 +66,11 @@ assert_equal 'hello world', Psych.parse_file(name).transform end + + def test_degenerate_strings + assert_equal false, Psych.load(' ') + assert_equal false, Psych.parse(' ') + assert_equal false, Psych.load('') + assert_equal false, Psych.parse('') + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/