mirror of
https://github.com/ruby/ruby.git
synced 2026-10-28 16:36:20 +08:00
[ruby/openssl] ssl: align #write and #<< with IO
IO#write and IO#<< convert the arguments to String with #to_s. RDoc comments for OpenSSL::Buffering#write also stated this, but they do not actually convert. Fix this. OpenSSL::Buffering#puts and #print already correctly call #to_s. https://github.com/ruby/openssl/commit/a801f1e957
This commit is contained in:
1 parent
f4a0d53e28
commit
ce8da0cfc0
2 files changed
+16
-3
No files matched your search
@@ -463,10 +463,13 @@ module OpenSSL::Buffering
|
||||
# converted using +.to_s+ method. Returns the number of bytes written.
|
||||
|
||||
def write(*s)
|
||||
s.inject(0) do |written, str|
|
||||
written = 0
|
||||
s.each do |str|
|
||||
str = str.to_s
|
||||
do_write(str)
|
||||
written + str.bytesize
|
||||
written += str.bytesize
|
||||
end
|
||||
written
|
||||
end
|
||||
|
||||
##
|
||||
@@ -516,7 +519,7 @@ module OpenSSL::Buffering
|
||||
# +.to_s+ method.
|
||||
|
||||
def <<(s)
|
||||
do_write(s)
|
||||
do_write(s.to_s)
|
||||
self
|
||||
end
|
||||
|
||||
|
||||
@@ -600,6 +600,16 @@ module OpenSSL::TestPairM
|
||||
}
|
||||
end
|
||||
|
||||
def test_write_ltlt_convert_to_s
|
||||
ssl_pair {|s1, s2|
|
||||
def (obj = Object.new).to_s() "obj" end
|
||||
assert_equal(6, s1.write("str", obj))
|
||||
assert_same(s1, s1 << obj)
|
||||
s1.close
|
||||
assert_equal("strobjobj", s2.read)
|
||||
}
|
||||
end
|
||||
|
||||
def test_write_zero
|
||||
ssl_pair {|s1, s2|
|
||||
assert_equal 0, s2.write_nonblock('', exception: false)
|
||||
|
||||
Reference in new issue
Block a user