Skip to content

Commit

Permalink
* ext/psych/lib/psych.rb (load, parse): stop parsing or loading after
Browse files Browse the repository at this point in the history
  the first document has been parsed.

* test/psych/test_stream.rb: pertinent tests.
  • Loading branch information
tenderlove committed Mar 8, 2012
1 parent 34d3b22 commit f506d5e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rdoc
@@ -1,3 +1,10 @@
Fri Mar 9 06:29:22 2012 Aaron Patterson <aaron@tenderlovemaking.com>

* ext/psych/lib/psych.rb (load, parse): stop parsing or loading after
the first document has been parsed.

* test/psych/test_stream.rb: pertinent tests.

Fri Mar 9 06:17:05 2012 Aaron Patterson <aaron@tenderlovemaking.com>

* ext/psych/lib/psych.rb (parse_stream, load_stream): if a block is
Expand Down
6 changes: 4 additions & 2 deletions lib/psych.rb
Expand Up @@ -148,8 +148,10 @@ def self.load yaml, filename = nil
#
# See Psych::Nodes for more information about YAML AST.
def self.parse yaml, filename = nil
children = parse_stream(yaml, filename).children
children.empty? ? false : children.first.children.first
parse_stream(yaml, filename) do |node|
return node
end
false
end

###
Expand Down
10 changes: 10 additions & 0 deletions test/psych/test_stream.rb
Expand Up @@ -2,6 +2,16 @@

module Psych
class TestStream < TestCase
def test_parse_partial
rb = Psych.parse("--- foo\n...\n--- `").to_ruby
assert_equal 'foo', rb
end

def test_load_partial
rb = Psych.load("--- foo\n...\n--- `")
assert_equal 'foo', rb
end

def test_parse_stream_yields_documents
list = []
Psych.parse_stream("--- foo\n...\n--- bar") do |doc|
Expand Down

0 comments on commit f506d5e

Please sign in to comment.