Permalink
Browse files

Additional IO encoding tweaks to get specs green again.

  • Loading branch information...
1 parent 5032ade commit 6406a20ccb95a7f597e60d48c2dbb9e369aae313 @headius headius committed May 16, 2012
Showing with 14 additions and 6 deletions.
  1. +12 −5 src/org/jruby/RubyIO.java
  2. +2 −1 src/org/jruby/util/io/EncodingOption.java
@@ -626,10 +626,17 @@ private IRubyObject getline(Ruby runtime, ByteList separator, long limit, ByteLi
Encoding external = externalEncoding;
if (internal != external) {
- result = RubyString.newStringNoCopy(runtime,
- RubyString.transcode(runtime.getCurrentContext(),
- ((RubyString) result).getByteList(), external, internal,
- runtime.getNil()));
+ ByteList transcoded = RubyString.transcode(
+ runtime.getCurrentContext(),
+ ((RubyString) result).getByteList(),
+ external, internal,
+ runtime.getNil());
+
+ RubyString newResult = RubyString.newStringNoCopy(runtime, transcoded);
+
+ newResult.infectBy(result);
+
+ result = newResult;
}
}
@@ -3289,7 +3296,7 @@ public static IRubyObject foreachInternal(ThreadContext context, IRubyObject rec
runtime.checkSafeString(filename);
RubyIO io = (RubyIO)RubyFile.open(context, runtime.getFile(), new IRubyObject[] { filename }, Block.NULL_BLOCK);
-
+
ByteListCache cache = new ByteListCache();
if (!io.isNil()) {
try {
@@ -100,8 +100,9 @@ private static EncodingOption createEncodingOption(Ruby runtime, Encoding extEnc
}
if (intEncoding == null || intEncoding == extEncoding) {
/* No internal encoding => use external + no transcoding */
+ // JRuby passes extEncoding instead of null for external, since we use this for final encoding of strings
return new EncodingOption(
- null,
+ extEncoding,
(defaultExt && intEncoding != extEncoding) ? null : extEncoding,
isBom);
} else {

0 comments on commit 6406a20

Please sign in to comment.