Skip to content

Implement chomp: option for gets, readline, readlines, each_line - #503

Closed
casperisfine wants to merge 1 commit into
ruby:masterfrom
casperisfine:gets-chomp
Closed

casperisfine wants to merge 1 commit into
ruby:masterfrom
casperisfine:gets-chomp

Conversation

@casperisfine

@casperisfine casperisfine commented Mar 16, 2022 •

Copy link
Copy Markdown

It was added to IO methods in Ruby 2.4, but OpenSSL sockets don't have
them, so any code accepting SSL sockets can't make use of it.

Ref: ruby/ruby@a2144bd

cc @nobu since you implemented this in IO.

On another note, this led me to notice that SSLSocket#gets(nil) and SSLSocket#gets("") aren't supported either.

@nobu

nobu commented Mar 20, 2022

Copy link
Copy Markdown
Member

Seems fine.
The failure on mswin should be fixed by rebase.

Comment thread test/openssl/test_ssl.rb Outdated
@rhenium

rhenium commented Mar 21, 2022

Copy link
Copy Markdown
Member

Thanks for working on this! This is indeed overlooked and should be implemented.

Unlike IO#gets, OpenSSL::Buffering/OpenSSL::SSL::SSLSocket#gets accepts a Regexp as the eol parameter. Should this be made compatible with chomp option too? Or perhaps it can simply be documented as unsupported... I didn't know #gets took a Regexp at all.

On another note, this led me to notice that SSLSocket#gets(nil) and SSLSocket#gets("") aren't supported either.

I think that should be aligned with IO too, as these currently don't give any useful return value.

@casperisfine

Copy link
Copy Markdown
Author

Unlike IO#gets, OpenSSL::Buffering/OpenSSL::SSL::SSLSocket#gets accepts a Regexp as the eol parameter. Should this be made compatible with chomp option too?

um, so we'd need to chomp whatever the regexp matched? Seems tricky.

…line`

It was added to IO methods in Ruby 2.4, but OpenSSL sockets don't have
them, so any code accepting SSL sockets can't make use of it.

Ref: ruby/ruby@a2144bd
@rhenium

rhenium commented Oct 16, 2026

Copy link
Copy Markdown
Member

#708 added initial support for chomp: true in 2023.

There was also some related refactoring in #1104.

@rhenium rhenium closed this Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants