Skip to content

Commit d7b37c0

Browse files
committed
ext/spl: Fix default argument handling for named parameters in SplFileObject::fgetcsv()
1 parent d8a5aec commit d7b37c0

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

ext/spl/spl_directory.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2268,7 +2268,9 @@ PHP_METHOD(SplFileObject, fgetcsv)
22682268
zend_argument_value_error(1, "must be a single character");
22692269
RETURN_THROWS();
22702270
}
2271-
delimiter = delim[0];
2271+
if(delim[0] != ',') {
2272+
delimiter = delim[0];
2273+
}
22722274
}
22732275
if (enclo) {
22742276
if (e_len != 1) {

ext/spl/tests/gh22156.phpt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Bug GH-22156 SplFileObject::fgetcsv() with named escape parameter
3+
--FILE--
4+
<?php
5+
6+
$file = new SplFileObject('php://memory', 'rw+');
7+
8+
$file->fwrite("foo;bar;baz");
9+
$file->seek(0);
10+
11+
$file->setCsvControl(';', "\n", "\\");
12+
13+
while (!$file->eof()) {
14+
$line = $file->fgetcsv(escape: '\\');
15+
var_dump($line);
16+
}
17+
18+
?>
19+
--EXPECT--
20+
array(3) {
21+
[0]=>
22+
string(3) "foo"
23+
[1]=>
24+
string(3) "bar"
25+
[2]=>
26+
string(3) "baz"
27+
}
28+

0 commit comments

Comments
 (0)