Skip to content
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

Verifying if character is corrupted, meaning that one more char is needed. #682

Merged
merged 1 commit into from
Apr 30, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion spec/tags/1.9/ruby/core/io/foreach_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:IO.foreach when the filename starts with | gets data from a fork when passed -
fails:IO.foreach when passed name, object when the object is a Fixnum uses the object as a limit if it is a Fixnum
1 change: 0 additions & 1 deletion spec/tags/1.9/ruby/core/io/readlines_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:IO#readlines when passed a string that starts with a | gets data from a fork when passed -
fails:IO.readlines when passed name, object when the object is a Fixnum uses the object as a limit if it is a Fixnum
6 changes: 6 additions & 0 deletions src/org/jruby/RubyIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
import org.jruby.util.CharsetTranscoder;
import org.jruby.util.ShellLauncher.POpenProcess;
import org.jruby.util.io.IOEncodable;
import static org.jruby.util.StringSupport.isIncompleteChar;

/**
*
Expand Down Expand Up @@ -664,6 +665,11 @@ private IRubyObject getlineInner(Ruby runtime, ByteList separator, long limit, B
n = readStream.getline(buf, (byte) newline);
} else {
n = readStream.getline(buf, (byte) newline, limit);

if (buf.length() > 0 && isIncompleteChar(buf.get(buf.length() - 1))) {
buf.append((byte)readStream.fgetc());
}

limit -= n;
if (limit <= 0) {
update = limitReached = true;
Expand Down
5 changes: 5 additions & 0 deletions src/org/jruby/util/StringSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -524,4 +524,9 @@ public static String escapedCharFormat(int c, boolean isUnicode) {
return format;
}

// mri: ONIGENC_MBCLEN_NEEDMORE_P - onigurama.h
public static boolean isIncompleteChar(int b) {
return b < -1;
}

}