-
-
Notifications
You must be signed in to change notification settings - Fork 925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Socket.gethostname ignores encoding settings #2558
Comments
MRI 2.1.4 also has this bug. |
I believe this would fix it. I noticed gethostbyname and others are not using this path either. If someone can confirm this fix (I'm on Windows and struggling with dev env at the moment), we can get it merged in. diff --git a/core/src/main/java/org/jruby/ext/socket/SocketUtils.java b/core/src/main/java/org/jruby/ext/socket/SocketUtils.java
index b1a457e..65110a7 100644
--- a/core/src/main/java/org/jruby/ext/socket/SocketUtils.java
+++ b/core/src/main/java/org/jruby/ext/socket/SocketUtils.java
@@ -74,12 +74,12 @@ public class SocketUtils {
Ruby runtime = context.runtime;
try {
- return runtime.newString(InetAddress.getLocalHost().getHostName());
+ return RubyString.newInternalFromJavaExternal(runtime, InetAddress.getLocalHost().getHostName());
} catch(UnknownHostException e) {
try {
- return runtime.newString(InetAddress.getByAddress(new byte[]{0,0,0,0}).getHostName());
+ return RubyString.newInternalFromJavaExternal(runtime, InetAddress.getByAddress(new byte[]{0, 0, 0, 0}).getHostName());
} catch(UnknownHostException e2) {
throw sockerr(runtime, "gethostname: name or service not known"); I'm confused why it would be Windows-1252, though. At least on 9k, the logic for |
Fixed in 9k.rc2 and 1.7.21. |
This is still an issue on 1.7.22
|
a shout out that this is still an issue in 1.7.25-snapshot as of 12th of april 2016:
|
While I agree that it's a bit confusing, neither |
an update here, most of these respect
|
@kares And CRuby does this differently I assume? There's no examples on MRI. |
sorry, did not want to get into the hustle of installing MRI on Windows 😒 in either case, ENV keys/values are platform specific regardless of setting external.
|
Still unclear whether there's a difference from MRI here. If so, someone should open a separate bug for that since the original issue here was patched and closed (though maybe not fixed the way everyone wants). If both JRuby and MRI have the same bug here, then we'd need to work with ruby-core to determine if this should be fixed. JRuby will follow MRI's lead. |
tested on windows but also happens on macosx. I can't make Socket.gethostname return a UTF-8 string even when fiddling with Encoding.default_internal and external settings.
Example:
The text was updated successfully, but these errors were encountered: