diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-03-29 16:01:14 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-03-29 16:01:14 -0700 |
commit | 9240b5eb7b256101a0d260fce529880994b10ac6 (patch) | |
tree | a10195f0ee6206fced41ea01bde72a0d44616757 | |
parent | bf87dcd2e63abeb8fe38a20dfef7f933661be1c8 (diff) | |
parent | c5f84428d51d85cee7fffef90b21da162c5d2258 (diff) | |
download | psych-9240b5eb7b256101a0d260fce529880994b10ac6.zip |
Merge remote branch 'pbm/master'
* pbm/master:
Fix problem with empty and white-space only strings. Add test.
-rw-r--r-- | lib/psych.rb | 6 | ||||
-rw-r--r-- | test/psych/test_psych.rb | 7 |
2 files changed, 11 insertions, 2 deletions
diff --git a/lib/psych.rb b/lib/psych.rb index 574bc7e..c142593 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 fce070f..88fe83c 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 |