Align the behavior of SSLSocket's IO-compatible methods with core IO - #1104
Open
rhenium wants to merge 9 commits into
Open
Align the behavior of SSLSocket's IO-compatible methods with core IO#1104rhenium wants to merge 9 commits into
rhenium wants to merge 9 commits into
Conversation
The Buffer class is an implementation detail. It will be removed once ruby/openssl starts to require Ruby 3.4 or later, where String#append_as_bytes is always available.
Allow OpenSSL::Buffering#ungetc to take String, not just Integer. Add OpenSSL::Buffering#ungetbyte with the consistent behavior with IO#ungetbyte in Ruby >= 1.9.
Let OpenSSL::Buffering#each_byte return an Enumerator if called without a block. Add the #each_char variant for compatibility with Ruby 1.9 IO.
Rewrite OpenSSL::Buffering#gets to handle parameters as closely to core
IO as possible. This includes changes:
- Add support for the calling form"gets(limit), where the rs is
omitted.
- Add support for rs=nil (slurp mode).
- Add support for rs="" (paragraph mode).
- Enforce limit correctly when EOF is reached before rs.
- Do not attempt to read from the socket when limit=0 is passed.
- Let #each_line, #readlines, and #readline forward all arguments to
#gets, not just the rs.
IO#write and IO#<< convert the arguments to String with #to_s. OpenSSL::Buffering#write also documented the intended behavior, but the implementation does not actually convert. Fix this. OpenSSL::Buffering#puts and #print already correctly call #to_s.
IO#syswrite converts the argument with #to_s rather than #to_str.
Handle arrays and nested arrays in OpenSSL::Buffering#puts in a similar fashion as IO#puts.
OpenSSL::Buffering already supports other character IO methods such as #getc, #ungetc, or #readchar. Add the missing method.
rhenium
force-pushed
the
ky/ssl-io-methods-updates
branch
from
September 2, 2026 11:20
919b916 to
01c3142
Compare
Run assertions in test_pair.rb against a pair of real socket objects to avoid accidentally introducing incompatible changes in SSLSocket or OpenSSL::Buffering.
rhenium
force-pushed
the
ky/ssl-io-methods-updates
branch
from
September 2, 2026 17:22
01c3142 to
bc43561
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Update the following methods on
OpenSSL::Bufferingfor better consistency with IO in modern Ruby:#ungetc: Accept strings.#each_byte: ReturnEnumeratorif called without a block.#gets: Really complex method and had many issues. I've tried to match the behavior as closely as possible.#write,#<<,#syswrite,#write_nonblock: Convert arguments withto_srather thanto_str.#each_char,#puts,#ungetbyte: Added missing methods.Also run the same tests against actual
IOobjects to catch accidental discrepancy.