-
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 GH-8121: SplFileObject - seek and key with csv file inconsistent
First, we must not free the current line before we call `spl_filesystem_file_read_csv()`, because then the `current_line` will not be properly updated. Since the EOF check is superfluous here, we move that part of the code to the branch for subtypes. This issue has been introduced by the fix for bug 75917. Second, we only must increase the `current_line` if we're not reading ahead. This issue has been introduced by the fix for bug 62004. Closes GH-8138.
- Loading branch information
Showing
4 changed files
with
55 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
id,status,on_sale,brand,name,link,meta_title,meta_desc,description | ||
1,2,15,Samsung,M21,samsung-m21,Samsung M21,Samsung M21,Samsung M21 | ||
2,2,15,Samsung,M32,samsung-m32,Samsung M32,Samsung M32,Samsung M32 | ||
3,2,15,Samsung,M21,samsung-m21,Samsung M21,Samsung M21,Samsung M21 | ||
4,2,15,Samsung,M32,samsung-m32,Samsung M32,Samsung M32,Samsung M32 |
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,39 @@ | ||
--TEST-- | ||
GH-8121 (SplFileObject - seek and key with csv file inconsistent) | ||
--FILE-- | ||
<?php | ||
$flagss = [ | ||
SplFileObject::READ_AHEAD | SplFileObject::READ_CSV | SplFileObject::SKIP_EMPTY | SplFileObject::DROP_NEW_LINE, | ||
SplFileObject::READ_AHEAD | SplFileObject::SKIP_EMPTY | SplFileObject::DROP_NEW_LINE, | ||
SplFileObject::SKIP_EMPTY | SplFileObject::DROP_NEW_LINE, | ||
]; | ||
foreach ($flagss as $flags) { | ||
$file = new SplFileObject(__DIR__ . "/gh8121.csv", "r"); | ||
echo "flags: $flags\n"; | ||
$file->setFlags($flags); | ||
$file->seek(0); | ||
var_dump($file->key()); | ||
$file->seek(1); | ||
var_dump($file->key()); | ||
$file->seek(2); | ||
var_dump($file->key()); | ||
$file->seek(3); | ||
var_dump($file->key()); | ||
} | ||
?> | ||
--EXPECT-- | ||
flags: 15 | ||
int(0) | ||
int(1) | ||
int(2) | ||
int(3) | ||
flags: 7 | ||
int(0) | ||
int(1) | ||
int(2) | ||
int(3) | ||
flags: 5 | ||
int(0) | ||
int(1) | ||
int(2) | ||
int(3) |