Permalink
Browse files

JRUBY-2075: IO#gets failures with latest rubyspecs (tainting, lineno,…

… $.)

git-svn-id: http://svn.codehaus.org/jruby/trunk/jruby@5920 961051c9-f516-0410-bf72-c9f7e237a7b7
  • Loading branch information...
1 parent 0cd8073 commit d41564a5208b9b33d268cef43be31693849a064c @vvs vvs committed Feb 12, 2008
View
@@ -614,6 +614,7 @@ public IRubyObject getline(ByteList separator) {
if (((RubyString)str).getByteList().length() == 0) {
return getRuntime().getNil();
}
+ incrementLineno(myOpenFile);
return str;
} else if (separator.length() == 1) {
return getlineFast(separator.get(0));
@@ -638,12 +639,7 @@ public IRubyObject getline(ByteList separator) {
if (c == -1) {
// TODO: clear error, wait for it to become readable
- if (c == -1) {
- if (update) {
- return RubyString.newString(getRuntime(), buf);
- }
- break;
- }
+ break;
}
buf.append(c);
@@ -674,9 +670,7 @@ public IRubyObject getline(ByteList separator) {
if (!update) {
return getRuntime().getNil();
} else {
- myOpenFile.setLineNumber(myOpenFile.getLineNumber() + 1);
- // this is for a range check, near as I can tell
- RubyNumeric.int2fix(getRuntime(), myOpenFile.getLineNumber());
+ incrementLineno(myOpenFile);
RubyString str = RubyString.newString(getRuntime(), buf);
str.setTaint(true);
@@ -695,7 +689,16 @@ public IRubyObject getline(ByteList separator) {
throw getRuntime().newIOError(e.getMessage());
}
}
-
+
+ private void incrementLineno(OpenFile myOpenFile) {
+ Ruby runtime = getRuntime();
+ int lineno = myOpenFile.getLineNumber() + 1;
+ myOpenFile.setLineNumber(lineno);
+ runtime.getGlobalVariables().set("$.", runtime.newFixnum(lineno));
+ // this is for a range check, near as I can tell
+ RubyNumeric.int2fix(getRuntime(), myOpenFile.getLineNumber());
+ }
+
protected boolean swallow(int term) throws IOException, BadDescriptorException {
Stream readStream = openFile.getMainStream();
int c;
@@ -736,12 +739,7 @@ public IRubyObject getlineFast(int delim) throws IOException, BadDescriptorExcep
if (c == -1) {
// TODO: clear error, wait for it to become readable
- if (c == -1) {
- if (update) {
- return RubyString.newString(getRuntime(), buf);
- }
- break;
- }
+ break;
}
buf.append(c);
@@ -752,9 +750,7 @@ public IRubyObject getlineFast(int delim) throws IOException, BadDescriptorExcep
if (!update) {
return getRuntime().getNil();
} else {
- openFile.setLineNumber(openFile.getLineNumber() + 1);
- // this is for a range check, near as I can tell
- RubyNumeric.int2fix(getRuntime(), openFile.getLineNumber());
+ incrementLineno(openFile);
RubyString str = RubyString.newString(getRuntime(), buf);
str.setTaint(true);
@@ -1 +0,0 @@
-IO::foreach updates $. with each yield
@@ -1,3 +0,0 @@
-IO#gets returns tainted strings
-IO#gets updates lineno with each invocation
-IO#gets updates $. with each invocation

0 comments on commit d41564a

Please sign in to comment.