From 240c9acb5c3ee0b3d538cf9ba12cb27f5e469dca Mon Sep 17 00:00:00 2001 From: tenderlove Date: Thu, 8 Mar 2012 21:31:05 +0000 Subject: [PATCH] * 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34954 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ ext/psych/lib/psych.rb | 6 ++++-- test/psych/test_stream.rb | 10 ++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index e52cdcf9ec..45ac98fee8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Fri Mar 9 06:29:22 2012 Aaron Patterson + + * 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 * ext/psych/lib/psych.rb (parse_stream, load_stream): if a block is diff --git a/ext/psych/lib/psych.rb b/ext/psych/lib/psych.rb index 69f3a7c1fe..df3acc0aff 100644 --- a/ext/psych/lib/psych.rb +++ b/ext/psych/lib/psych.rb @@ -148,8 +148,10 @@ module Psych # # 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 ### diff --git a/test/psych/test_stream.rb b/test/psych/test_stream.rb index 9807207661..beca365608 100644 --- a/test/psych/test_stream.rb +++ b/test/psych/test_stream.rb @@ -2,6 +2,16 @@ require 'psych/helper' 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|