Skip to content

Commit 5b099ff

Browse files
committed
[GR-18163] Update IO.readlines to ignore negative limit parameters
PullRequest: truffleruby/3228
2 parents dc27f35 + e72cbbd commit 5b099ff

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
@@ -45,6 +45,7 @@ Compatibility:
4545
* Update `String#lstrip!` to remove leading null characters (#2607, @bjfish).
4646
* Update `File.utime` to return the number of file names in the arguments (#2616, @bjfish).
4747
* Update `Dir.foreach` to accept an `encoding` parameter (#2627, @bjfish).
48+
* Update `IO.readlines` to ignore negative limit parameters (#2625 , @bjfish).
4849

4950
Performance:
5051

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)