Skip to content

Commit

Permalink
Use file.encoding for "filesystem" encoding on Windows.
Browse files Browse the repository at this point in the history
Fixes #3871.
  • Loading branch information
headius committed May 11, 2016
1 parent 46191a3 commit 1ceddaa
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions core/src/main/java/org/jruby/runtime/encoding/EncodingService.java
Expand Up @@ -10,6 +10,7 @@
import org.jcodings.util.Hash.HashEntryIterator;
import org.jruby.Ruby;
import org.jruby.RubyEncoding;
import org.jruby.exceptions.RaiseException;
import org.jruby.platform.Platform;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.ByteList;
Expand All @@ -25,6 +26,7 @@
import org.jruby.RubyFixnum;
import org.jruby.RubyString;
import org.jruby.ext.nkf.RubyNKF;
import org.jruby.util.SafePropertyAccessor;
import org.jruby.util.encoding.ISO_8859_16;

public final class EncodingService {
Expand Down Expand Up @@ -542,8 +544,15 @@ public Encoding toEncoding(Ruby runtime) {
case EXTERNAL: return runtime.getDefaultExternalEncoding();
case INTERNAL: return runtime.getDefaultInternalEncoding();
case FILESYSTEM:
// This needs to do something different on Windows. See encoding.c,
// in the enc_set_filesystem_encoding function.
if (Platform.IS_WINDOWS) {
String fileEncoding = SafePropertyAccessor.getProperty("file.encoding", "UTF-8");
try {
return service.getEncodingFromString(fileEncoding);
} catch (RaiseException re) {
runtime.getWarnings().warning("could not load encoding for file.encoding of " + fileEncoding + ", using default external");
if (runtime.isDebug()) re.printStackTrace();
}
}
return runtime.getDefaultExternalEncoding();
default:
throw new RuntimeException("invalid SpecialEncoding: " + this);
Expand Down

0 comments on commit 1ceddaa

Please sign in to comment.