diff --git a/ChangeLog b/ChangeLog index dca56eba02..9f541a671e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Tue Mar 30 08:10:59 2010 Aaron Patterson + + * 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 * lib/psych.rb: documentation updates. Thanks Peter McLain! diff --git a/lib/psych.rb b/lib/psych.rb index 574bc7e641..c14259373a 100644 --- a/lib/psych.rb +++ b/lib/psych.rb @@ -101,7 +101,8 @@ module Psych # 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 @@ module Psych # # 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 ### diff --git a/test/psych/test_psych.rb b/test/psych/test_psych.rb index fce070fa39..88fe83c19a 100644 --- a/test/psych/test_psych.rb +++ b/test/psych/test_psych.rb @@ -66,4 +66,11 @@ class TestPsych < Psych::TestCase 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