mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/psych.rb: Fix problem with empty and white-space only strings.
Thanks Peter McLain! * test/psych/test_psych.rb: tests for change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27099 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c294fcc0ab
commit
797f482fe8
3 changed files with 17 additions and 2 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
Tue Mar 30 08:10:59 2010 Aaron Patterson <aaron@tenderlovemaking.com>
|
||||||
|
|
||||||
|
* 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@tenderlovemaking.com>
|
Tue Mar 30 05:31:39 2010 Aaron Patterson <aaron@tenderlovemaking.com>
|
||||||
|
|
||||||
* lib/psych.rb: documentation updates. Thanks Peter McLain!
|
* lib/psych.rb: documentation updates. Thanks Peter McLain!
|
||||||
|
|
|
@ -101,7 +101,8 @@ module Psych
|
||||||
# Psych.load("--- a") # => 'a'
|
# Psych.load("--- a") # => 'a'
|
||||||
# Psych.load("---\n - a\n - b") # => ['a', 'b']
|
# Psych.load("---\n - a\n - b") # => ['a', 'b']
|
||||||
def self.load yaml
|
def self.load yaml
|
||||||
parse(yaml).to_ruby
|
result = parse(yaml)
|
||||||
|
result ? result.to_ruby : result
|
||||||
end
|
end
|
||||||
|
|
||||||
###
|
###
|
||||||
|
@ -113,7 +114,8 @@ module Psych
|
||||||
#
|
#
|
||||||
# See Psych::Nodes for more information about YAML AST.
|
# See Psych::Nodes for more information about YAML AST.
|
||||||
def self.parse yaml
|
def self.parse yaml
|
||||||
parse_stream(yaml).children.first.children.first
|
children = parse_stream(yaml).children
|
||||||
|
children.empty? ? false : children.first.children.first
|
||||||
end
|
end
|
||||||
|
|
||||||
###
|
###
|
||||||
|
|
|
@ -66,4 +66,11 @@ class TestPsych < Psych::TestCase
|
||||||
|
|
||||||
assert_equal 'hello world', Psych.parse_file(name).transform
|
assert_equal 'hello world', Psych.parse_file(name).transform
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue