From d4f5b77d3ab62c0b05feb2897bf93b2b3032dfeb Mon Sep 17 00:00:00 2001 From: gotoyuzo Date: Mon, 17 Dec 2007 07:06:16 +0000 Subject: [PATCH] * ext/openssl/lib/openssl/buffering.rb (Buffering#gets): added second optional argument to specify maximum length limit. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ ext/openssl/lib/openssl/buffering.rb | 5 ++++- test/openssl/test_ssl.rb | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 7045f92670..af8ca96453 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Mon Dec 17 16:04:16 2007 GOTOU Yuuzou + + * ext/openssl/lib/openssl/buffering.rb (Buffering#gets): added second + optional argument to specify maximum length limit. + Mon Dec 17 16:02:30 2007 GOTOU Yuuzou * lib/webrick/httprequest.rb, lib/webrick/cgi.rb: Request-Line or diff --git a/ext/openssl/lib/openssl/buffering.rb b/ext/openssl/lib/openssl/buffering.rb index 8800aa53cc..5dabcd5135 100644 --- a/ext/openssl/lib/openssl/buffering.rb +++ b/ext/openssl/lib/openssl/buffering.rb @@ -99,7 +99,7 @@ module Buffering ret end - def gets(eol=$/) + def gets(eol=$/, limit=nil) idx = @rbuffer.index(eol) until @eof break if idx @@ -111,6 +111,9 @@ module Buffering else size = idx ? idx+eol.size : nil end + if limit and limit >= 0 + size = [size, limit].min + end consume_rbuff(size) end diff --git a/test/openssl/test_ssl.rb b/test/openssl/test_ssl.rb index b99b4a30b0..5aee96e4fa 100644 --- a/test/openssl/test_ssl.rb +++ b/test/openssl/test_ssl.rb @@ -136,6 +136,11 @@ class OpenSSL::TestSSL < Test::Unit::TestCase str = "x" * 100 + "\n" ssl.puts(str) assert_equal(str, ssl.gets) + + str = "x" * 100 + ssl.puts(str) + assert_equal(str, ssl.gets("\n", 100)) + assert_equal("\n", ssl.gets) } # read and write