From 892eb6c58edbe4ca062b15587892d12a35715952 Mon Sep 17 00:00:00 2001 From: kares Date: Tue, 13 Feb 2024 16:52:41 +0100 Subject: [PATCH] [fix] SSLSocket#alpn_protocol to be nil when not used fixes GH-287 --- src/main/java/org/jruby/ext/openssl/SSLSocket.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jruby/ext/openssl/SSLSocket.java b/src/main/java/org/jruby/ext/openssl/SSLSocket.java index 31edcafa..63bbc07b 100644 --- a/src/main/java/org/jruby/ext/openssl/SSLSocket.java +++ b/src/main/java/org/jruby/ext/openssl/SSLSocket.java @@ -244,7 +244,10 @@ private SSLEngine ossl_ssl_setup(final ThreadContext context, final boolean serv @JRubyMethod(name = "alpn_protocol") public IRubyObject alpn_protocol(final ThreadContext context) { final String protocol = engine.getApplicationProtocol(); - return protocol == null ? context.nil : RubyString.newString(context.runtime, protocol); + // null if it has not yet been determined if alpn might be used for this connection, + // an empty String if application protocols values will not be used, + if (protocol == null || protocol.isEmpty()) return context.nil; + return RubyString.newString(context.runtime, protocol); } @JRubyMethod(name = "sync")