Skip to content

Commit

Permalink
JRUBY-6425: StringIO.readline of UTF-8 string will return a ASCII-8BIT
Browse files Browse the repository at this point in the history
  • Loading branch information
enebo committed Feb 8, 2012
1 parent 51b5524 commit d2af6e8
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/org/jruby/RubyStringIO.java
Expand Up @@ -376,26 +376,24 @@ private IRubyObject internalGets(ThreadContext context, IRubyObject[] args) {

if (data.pos < data.internal.getByteList().getRealSize() && !data.eof) {
boolean isParagraph = false;
boolean is19 = runtime.is1_9();
ByteList sep = ((RubyString)runtime.getGlobalVariables().get("$/")).getByteList();
IRubyObject sepArg = null;
int limit = -1;

if (context.getRuntime().is1_9()) {
if (is19) {
IRubyObject limitArg = (args.length > 1 ? args[1] :
(args.length > 0 && args[0] instanceof RubyFixnum ? args[0] :
null));
if (limitArg != null) {
limit = RubyNumeric.fix2int(limitArg);
}

sepArg = (args.length > 0 && !(args[0] instanceof RubyFixnum) ? args[0] :
null);
}
else {
sepArg = (args.length > 0 && !(args[0] instanceof RubyFixnum) ? args[0] : null);
} else {
sepArg = (args.length > 0 ? args[0] : null);
}


if (sepArg != null) {
if (sepArg.isNil()) {
int bytesAvailable = data.internal.getByteList().getRealSize() - (int)data.pos;
Expand Down Expand Up @@ -439,6 +437,7 @@ private IRubyObject internalGets(ThreadContext context, IRubyObject[] args) {
int bytesToUseWithSep = (limit < 0 || limit >= bytesWithSep ? bytesWithSep : limit);

ByteList line = new ByteList(bytesToUseWithSep);
if (is19) line.setEncoding(data.internal.getByteList().getEncoding());
line.append(data.internal.getByteList(), (int)data.pos, bytesToUse);
data.pos += bytesToUse;

Expand Down

0 comments on commit d2af6e8

Please sign in to comment.