Skip to content

Commit

Permalink
Merge pull request #6274 from headius/utf8_hostname
Browse files Browse the repository at this point in the history
Always encode gethostname result as UTF-8
  • Loading branch information
headius committed Jun 15, 2020
2 parents 03a8357 + a850980 commit 0742c00
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions core/src/main/java/org/jruby/ext/socket/SocketUtils.java
Expand Up @@ -33,6 +33,7 @@
import jnr.constants.platform.SocketOption;
import jnr.netdb.Protocol;
import jnr.netdb.Service;
import org.jcodings.specific.ASCIIEncoding;
import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyClass;
Expand Down Expand Up @@ -80,12 +81,12 @@ public static IRubyObject gethostname(ThreadContext context) {
Ruby runtime = context.runtime;

try {
return RubyString.newInternalFromJavaExternal(context.runtime, InetAddress.getLocalHost().getHostName());
return RubyString.newString(context.runtime, InetAddress.getLocalHost().getHostName());

} catch(UnknownHostException e) {

try {
return RubyString.newInternalFromJavaExternal(context.runtime, InetAddress.getByAddress(new byte[]{0, 0, 0, 0}).getHostName());
return RubyString.newString(context.runtime, InetAddress.getByAddress(new byte[]{0, 0, 0, 0}).getHostName());

} catch(UnknownHostException e2) {
throw sockerr(runtime, "gethostname: name or service not known");
Expand Down

0 comments on commit 0742c00

Please sign in to comment.