Skip to content

Commit

Permalink
foreach with limit 0 raises error now
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Mar 15, 2024
1 parent dd1ec75 commit 7ee4b54
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/src/main/java/org/jruby/RubyIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -2573,6 +2573,9 @@ public IRubyObject getline(ThreadContext context, RubyIO self, IRubyObject rs, i
private static final Getline.Callback<RubyIO, RubyIO> GETLINE_YIELD = new Getline.Callback<RubyIO, RubyIO>() {
@Override
public RubyIO getline(ThreadContext context, RubyIO self, IRubyObject rs, int limit, boolean chomp, Block block) {
if (limit == 0) {
throw context.runtime.newArgumentError("invalid limit: 0 for foreach");
}

IRubyObject line;
while ((line = self.getlineImpl(context, rs, limit, chomp)) != context.nil) {
Expand Down

0 comments on commit 7ee4b54

Please sign in to comment.