Permalink
Browse files

Fix JRUBY-5960: Something in rails causes File#each to throw InvalidB…

…yteSequenceError in 1.9 mode

* Binary mode should set external_encoding to ASCII8BIT.
  • Loading branch information...
1 parent cc2c489 commit a20c65200151fcba3c983da3888cedeb2c5e44d5 @headius headius committed Aug 16, 2011
Showing with 6 additions and 1 deletion.
  1. +6 −1 src/org/jruby/RubyFile.java
@@ -53,6 +53,7 @@
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
+import org.jcodings.specific.ASCIIEncoding;
import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
@@ -550,6 +551,7 @@ protected void sysopenInternal(String path, ModeFlags modes, int perm) throws In
openFile.setPath(path);
openFile.setMode(modes.getOpenFileFlags());
+ if (modes.isBinary()) externalEncoding = ASCIIEncoding.INSTANCE;
int umask = getUmaskSafe( getRuntime() );
perm = perm - (perm & umask);
@@ -562,14 +564,17 @@ protected void openInternal(String path, String modeString, ModeFlags modes) thr
openFile = new OpenFile();
openFile.setMode(modes.getOpenFileFlags());
+ if (modes.isBinary()) externalEncoding = ASCIIEncoding.INSTANCE;
openFile.setPath(path);
openFile.setMainStream(fopen(path, modeString));
}
protected void openInternal(String path, String modeString) throws InvalidValueException {
openFile = new OpenFile();
- openFile.setMode(getIOModes(getRuntime(), modeString).getOpenFileFlags());
+ ModeFlags modes = getIOModes(getRuntime(), modeString);
+ openFile.setMode(modes.getOpenFileFlags());
+ if (modes.isBinary()) externalEncoding = ASCIIEncoding.INSTANCE;
openFile.setPath(path);
openFile.setMainStream(fopen(path, modeString));
}

0 comments on commit a20c652

Please sign in to comment.