-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #62004: SplFileObject: fgets after seek returns wrong line
As it is, `::seek(0)` sets the file pointer to the beginning of the file, but `::seek($n)` where `$n > 0` sets the file pointer to the beginning of the following line, having line `$n` already read into the line buffer. This is pretty inconsistent; we fix it by always seeking to the beginning of the line. We also add a test case for the duplicate bug #46569. Closes GH-6434.
- Loading branch information
Showing
10 changed files
with
56 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,5 +26,5 @@ echo $s->current(); | |
--EXPECT-- | ||
//line 3 | ||
//line 4 | ||
//line 3 | ||
//line 4 | ||
//line 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
first,line | ||
second,line | ||
third,line | ||
fourth,line | ||
fifth,line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--TEST-- | ||
Bug #46569 (SplFileObject: fgetcsv after seek returns wrong line) | ||
--FILE-- | ||
<?php | ||
$file = new SplFileObject(__DIR__ . '/bug46569.csv'); | ||
$file->seek(1); | ||
print_r($file->fgetcsv()); | ||
?> | ||
--EXPECT-- | ||
Array | ||
( | ||
[0] => second | ||
[1] => line | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--TEST-- | ||
Bug #62004 (SplFileObject: fgets after seek returns wrong line) | ||
--FILE-- | ||
<?php | ||
$f = new SplFileObject(__DIR__ . '/bug62004.txt'); | ||
$f->setFlags(SplFileObject::SKIP_EMPTY); | ||
$f->seek(0); | ||
echo $f->fgets(); | ||
$f->seek(1); | ||
echo $f->fgets(); | ||
$f->seek(2); | ||
echo $f->fgets(); | ||
?> | ||
--EXPECT-- | ||
Line 1 | ||
Line 2 | ||
Line 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Line 1 | ||
Line 2 | ||
Line 3 | ||
Line 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,5 @@ echo $s->getCurrentLine(); | |
echo $s->getCurrentLine(); | ||
?> | ||
--EXPECT-- | ||
//line 2 | ||
//line 3 | ||
//line 4 |