openssl icon indicating copy to clipboard operation
openssl copied to clipboard

Implement `chomp:` option for `gets`, `readline`, `readlines`, `each_line`

Open casperisfine opened this issue 2 years ago • 3 comments

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: https://github.com/ruby/ruby/commit/a2144bd72aad7c25e160cf283f957d59fe7c90b2

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.

casperisfine avatar Mar 16 '22 12:03 casperisfine

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

nobu avatar Mar 20 '22 10:03 nobu

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.

rhenium avatar Mar 21 '22 10:03 rhenium

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.

casperisfine avatar Mar 21 '22 11:03 casperisfine