Skip to content

Commit e72cbbd

Browse files
committed
Update IO.readlines to ignore negative limit parameters
1 parent 44a5bf5 commit e72cbbd

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Compatibility:
4343
* Update `String#split` to raise `TypeError` when false is given (#2606, @bjfish).
4444
* Update `String#lstrip!` to remove leading null characters (#2607, @bjfish).
4545
* Update `File.utime` to return the number of file names in the arguments (#2616, @bjfish).
46+
* Update `IO.readlines` to ignore negative limit parameters (#2625 , @bjfish).
4647

4748
Performance:
4849

spec/ruby/core/io/shared/readlines.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@
7373
result = IO.send(@method, @name, 10, &@object)
7474
(result ? result : ScratchPad.recorded).should == IOSpecs.lines_limit
7575
end
76+
77+
it "ignores the object as a limit if it is negative" do
78+
result = IO.send(@method, @name, -2, &@object)
79+
(result ? result : ScratchPad.recorded).should == IOSpecs.lines
80+
end
7681
end
7782

7883
describe "when the object is a String" do

src/main/ruby/truffleruby/core/io.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ def self.foreach(name, separator=undefined, limit=undefined, options=undefined,
464464
options = Truffle::Type.coerce_to value, Hash, :to_hash
465465
end
466466
end
467+
limit = nil if limit && limit < 0
467468

468469
options = {} if Primitive.undefined?(options)
469470
case options

0 commit comments

Comments
 (0)