mirror of
https://github.com/php/php-src.git
synced 2026-03-25 16:52:18 +01:00
MFB: Improve fix for bug #48313
This commit is contained in:
@@ -2108,6 +2108,7 @@ PHPAPI void php_fgetcsv(php_stream *stream, char delimiter, char enclosure, char
|
||||
char *temp, *tptr, *bptr, *line_end, *limit;
|
||||
size_t temp_len, line_end_len;
|
||||
int inc_len;
|
||||
zend_bool first_field = 1;
|
||||
|
||||
/* initialize internal state */
|
||||
php_mblen(NULL, 0);
|
||||
@@ -2159,6 +2160,11 @@ PHPAPI void php_fgetcsv(php_stream *stream, char delimiter, char enclosure, char
|
||||
}
|
||||
|
||||
quit_loop_1:
|
||||
if (first_field && bptr == line_end) {
|
||||
add_next_index_null(return_value);
|
||||
break;
|
||||
}
|
||||
first_field = 0;
|
||||
/* 2. Read field, leaving bptr pointing at start of next field */
|
||||
if (inc_len != 0 && *bptr == enclosure) {
|
||||
int state = 0;
|
||||
@@ -2355,12 +2361,8 @@ PHPAPI void php_fgetcsv(php_stream *stream, char delimiter, char enclosure, char
|
||||
}
|
||||
|
||||
/* 3. Now pass our field back to php */
|
||||
if (comp_end - temp) {
|
||||
*comp_end = '\0';
|
||||
add_next_index_stringl(return_value, temp, comp_end - temp, 1);
|
||||
} else {
|
||||
add_next_index_null(return_value);
|
||||
}
|
||||
*comp_end = '\0';
|
||||
add_next_index_stringl(return_value, temp, comp_end - temp, 1);
|
||||
} while (inc_len > 0);
|
||||
|
||||
out:
|
||||
|
||||
@@ -75,7 +75,7 @@ echo "Done\n";
|
||||
-- Testing fgetcsv() with file opened using r mode --
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
NULL
|
||||
}
|
||||
int(1)
|
||||
bool(false)
|
||||
@@ -86,7 +86,7 @@ bool(true)
|
||||
-- Testing fgetcsv() with file opened using rb mode --
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
NULL
|
||||
}
|
||||
int(1)
|
||||
bool(false)
|
||||
@@ -97,7 +97,7 @@ bool(true)
|
||||
-- Testing fgetcsv() with file opened using rt mode --
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
NULL
|
||||
}
|
||||
int(1)
|
||||
bool(false)
|
||||
@@ -108,7 +108,7 @@ bool(true)
|
||||
-- Testing fgetcsv() with file opened using r+ mode --
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
NULL
|
||||
}
|
||||
int(1)
|
||||
bool(false)
|
||||
@@ -119,7 +119,7 @@ bool(true)
|
||||
-- Testing fgetcsv() with file opened using r+b mode --
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
NULL
|
||||
}
|
||||
int(1)
|
||||
bool(false)
|
||||
@@ -130,7 +130,7 @@ bool(true)
|
||||
-- Testing fgetcsv() with file opened using r+t mode --
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
NULL
|
||||
}
|
||||
int(1)
|
||||
bool(false)
|
||||
@@ -141,7 +141,7 @@ bool(true)
|
||||
-- Testing fgetcsv() with file opened using a+ mode --
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
NULL
|
||||
}
|
||||
int(1)
|
||||
bool(false)
|
||||
@@ -152,7 +152,7 @@ bool(true)
|
||||
-- Testing fgetcsv() with file opened using a+b mode --
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
NULL
|
||||
}
|
||||
int(1)
|
||||
bool(false)
|
||||
@@ -163,7 +163,7 @@ bool(true)
|
||||
-- Testing fgetcsv() with file opened using a+t mode --
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
NULL
|
||||
}
|
||||
int(1)
|
||||
bool(false)
|
||||
@@ -174,7 +174,7 @@ bool(true)
|
||||
-- Testing fgetcsv() with file opened using w+ mode --
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
NULL
|
||||
}
|
||||
int(1)
|
||||
bool(false)
|
||||
@@ -185,7 +185,7 @@ bool(true)
|
||||
-- Testing fgetcsv() with file opened using w+b mode --
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
NULL
|
||||
}
|
||||
int(1)
|
||||
bool(false)
|
||||
@@ -196,7 +196,7 @@ bool(true)
|
||||
-- Testing fgetcsv() with file opened using w+t mode --
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
NULL
|
||||
}
|
||||
int(1)
|
||||
bool(false)
|
||||
@@ -207,7 +207,7 @@ bool(true)
|
||||
-- Testing fgetcsv() with file opened using x+ mode --
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
NULL
|
||||
}
|
||||
int(1)
|
||||
bool(false)
|
||||
@@ -218,7 +218,7 @@ bool(true)
|
||||
-- Testing fgetcsv() with file opened using x+b mode --
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
NULL
|
||||
}
|
||||
int(1)
|
||||
bool(false)
|
||||
@@ -229,7 +229,7 @@ bool(true)
|
||||
-- Testing fgetcsv() with file opened using x+t mode --
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
NULL
|
||||
}
|
||||
int(1)
|
||||
bool(false)
|
||||
|
||||
@@ -72,7 +72,7 @@ echo "Done\n";
|
||||
-- Testing fgetcsv() with file opened using r mode --
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
NULL
|
||||
}
|
||||
int(1)
|
||||
bool(false)
|
||||
@@ -80,7 +80,7 @@ bool(false)
|
||||
-- Testing fgetcsv() with file opened using rb mode --
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
NULL
|
||||
}
|
||||
int(1)
|
||||
bool(false)
|
||||
@@ -88,7 +88,7 @@ bool(false)
|
||||
-- Testing fgetcsv() with file opened using rt mode --
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
NULL
|
||||
}
|
||||
int(1)
|
||||
bool(false)
|
||||
@@ -96,7 +96,7 @@ bool(false)
|
||||
-- Testing fgetcsv() with file opened using r+ mode --
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
NULL
|
||||
}
|
||||
int(1)
|
||||
bool(false)
|
||||
@@ -104,7 +104,7 @@ bool(false)
|
||||
-- Testing fgetcsv() with file opened using r+b mode --
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
NULL
|
||||
}
|
||||
int(1)
|
||||
bool(false)
|
||||
@@ -112,7 +112,7 @@ bool(false)
|
||||
-- Testing fgetcsv() with file opened using r+t mode --
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
NULL
|
||||
}
|
||||
int(1)
|
||||
bool(false)
|
||||
@@ -120,7 +120,7 @@ bool(false)
|
||||
-- Testing fgetcsv() with file opened using a+ mode --
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
NULL
|
||||
}
|
||||
int(1)
|
||||
bool(false)
|
||||
@@ -128,7 +128,7 @@ bool(false)
|
||||
-- Testing fgetcsv() with file opened using a+b mode --
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
NULL
|
||||
}
|
||||
int(1)
|
||||
bool(false)
|
||||
@@ -136,7 +136,7 @@ bool(false)
|
||||
-- Testing fgetcsv() with file opened using a+t mode --
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
NULL
|
||||
}
|
||||
int(1)
|
||||
bool(false)
|
||||
@@ -144,7 +144,7 @@ bool(false)
|
||||
-- Testing fgetcsv() with file opened using w+ mode --
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
NULL
|
||||
}
|
||||
int(1)
|
||||
bool(false)
|
||||
@@ -152,7 +152,7 @@ bool(false)
|
||||
-- Testing fgetcsv() with file opened using w+b mode --
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
NULL
|
||||
}
|
||||
int(1)
|
||||
bool(false)
|
||||
@@ -160,7 +160,7 @@ bool(false)
|
||||
-- Testing fgetcsv() with file opened using w+t mode --
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
NULL
|
||||
}
|
||||
int(1)
|
||||
bool(false)
|
||||
@@ -168,7 +168,7 @@ bool(false)
|
||||
-- Testing fgetcsv() with file opened using x+ mode --
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
NULL
|
||||
}
|
||||
int(1)
|
||||
bool(false)
|
||||
@@ -176,7 +176,7 @@ bool(false)
|
||||
-- Testing fgetcsv() with file opened using x+b mode --
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
NULL
|
||||
}
|
||||
int(1)
|
||||
bool(false)
|
||||
@@ -184,7 +184,7 @@ bool(false)
|
||||
-- Testing fgetcsv() with file opened using x+t mode --
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
NULL
|
||||
}
|
||||
int(1)
|
||||
bool(false)
|
||||
|
||||
Reference in New Issue
Block a user