Skip to content

Send the String from to_str in BasicSocket#send without a destination - #10111

Open
taxor03 wants to merge 1 commit into
jruby:jruby-10.0from
taxor03:fix-socket-send-to-str-10.0
Open

taxor03 wants to merge 1 commit into
jruby:jruby-10.0from
taxor03:fix-socket-send-to-str-10.0

Conversation

@taxor03

@taxor03 taxor03 commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Fixes #10105.

RubyBasicSocket#doSend converted the message with convertToString(), but only the DatagramChannel send to a destination address used the result. Without an address it passed the original object to syswrite, which writes its to_s, so a socket from UNIXSocket.pair, a TCP socket or a connected UDP socket sent "#<Object:...>" for an object that defines to_str. It now passes the converted String in both cases, and converts the message first, as rsock_bsock_send does with StringValue(arg.mesg) (basicsocket.c#L576).

This adds "sends the String returned by #to_str of an object" to spec/ruby/library/socket/basicsocket/send_spec.rb, for a connected UDP socket without a destination address. It fails before this change and passes after it, and passes on CRuby 4.0.9 and 3.4.12. Tested with spec/ruby/library/socket/basicsocket, udpsocket and unixsocket (also with -Xjit.threshold=0 and -X-C), test/mri/socket/test_basicsocket.rb, test_socket.rb, test_udp.rb, test_unix.rb and the fast RubySpec suite. No new failures.

The commit cherry-picks cleanly onto master, and the new spec passes there with the default parser and with -Xparser.prism.

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.

1 participant