summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlia Alshanetsky <iliaa@php.net>2009-05-24 16:01:48 +0000
committerIlia Alshanetsky <iliaa@php.net>2009-05-24 16:01:48 +0000
commit529bcf35c2ba2af80ffe712f00a61cc555ff468f (patch)
treebe41c32019739ac0309e2ebe8acc0184b0584961
parent0873648ef06c9a7db8c5085cc89fccb43f08fb76 (diff)
downloadphp-git-529bcf35c2ba2af80ffe712f00a61cc555ff468f.tar.gz
MFB: Improve fix for bug #48313
-rw-r--r--ext/standard/file.c14
-rw-r--r--ext/standard/tests/file/fgetcsv_variation14.phpt30
-rw-r--r--ext/standard/tests/file/fgetcsv_variation21.phpt30
3 files changed, 38 insertions, 36 deletions
diff --git a/ext/standard/file.c b/ext/standard/file.c
index f52275dde5..f2b6ea7294 100644
--- a/ext/standard/file.c
+++ b/ext/standard/file.c
@@ -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:
diff --git a/ext/standard/tests/file/fgetcsv_variation14.phpt b/ext/standard/tests/file/fgetcsv_variation14.phpt
index 8a64cafa7f..927bf8a077 100644
--- a/ext/standard/tests/file/fgetcsv_variation14.phpt
+++ b/ext/standard/tests/file/fgetcsv_variation14.phpt
@@ -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)
diff --git a/ext/standard/tests/file/fgetcsv_variation21.phpt b/ext/standard/tests/file/fgetcsv_variation21.phpt
index 69059bb2c9..e6a9ee586d 100644
--- a/ext/standard/tests/file/fgetcsv_variation21.phpt
+++ b/ext/standard/tests/file/fgetcsv_variation21.phpt
@@ -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)