ruby-changes:44608
From: a_matsuda <ko1@a...>
Date: Wed, 9 Nov 2016 05:25:49 +0900 (JST)
Subject: [ruby-changes:44608] a_matsuda:r56681 (trunk): Fix undefined method 'dump' for nil:NilClass (NoMethodError)
a_matsuda 2016-11-09 05:25:44 +0900 (Wed, 09 Nov 2016) New Revision: 56681 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56681 Log: Fix undefined method 'dump' for nil:NilClass (NoMethodError) Patch by: Dmitry Vorotilin <d.vorotilin@g...> (@route) Signed-off-by: Akira Matsuda <ronnie@d...> closes #1475 Modified files: trunk/lib/net/http/response.rb trunk/test/net/http/test_httpresponse.rb Index: lib/net/http/response.rb =================================================================== --- lib/net/http/response.rb (revision 56680) +++ lib/net/http/response.rb (revision 56681) @@ -117,7 +117,9 @@ class Net::HTTPResponse https://github.com/ruby/ruby/blob/trunk/lib/net/http/response.rb#L117 end def error! #:nodoc: - raise error_type().new(@code + ' ' + @message.dump, self) + message = @code + message += ' ' + @message.dump if @message + raise error_type().new(message, self) end def error_type #:nodoc: Index: test/net/http/test_httpresponse.rb =================================================================== --- test/net/http/test_httpresponse.rb (revision 56680) +++ test/net/http/test_httpresponse.rb (revision 56681) @@ -385,6 +385,22 @@ EOS https://github.com/ruby/ruby/blob/trunk/test/net/http/test_httpresponse.rb#L385 assert_equal(nil, res.message) end + def test_raises_exception_with_missing_reason + io = dummy_io(<<EOS) +HTTP/1.1 404 +Content-Length: 5 +Connection: close + +hello +EOS + + res = Net::HTTPResponse.read_new(io) + assert_equal(nil, res.message) + assert_raise Net::HTTPServerException do + res.error! + end + end + private def dummy_io(str) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/