]> granicus.if.org Git - php/commitdiff
MFB: Improve fix for bug #48313
authorIlia Alshanetsky <iliaa@php.net>
Sun, 24 May 2009 16:01:48 +0000 (16:01 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Sun, 24 May 2009 16:01:48 +0000 (16:01 +0000)
ext/standard/file.c
ext/standard/tests/file/fgetcsv_variation14.phpt
ext/standard/tests/file/fgetcsv_variation21.phpt

index f52275dde59a4eecee6255a6993fe67b1e8163fd..f2b6ea729405d041f490d5766f1763d857ae4937 100644 (file)
@@ -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:
index 8a64cafa7f711768941a6467cdf893c52fcada14..927bf8a077f729c53b1f9f04719f0220907628d4 100644 (file)
@@ -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)
index 69059bb2c9b9b147d432f5858ff7bc1e8f9a44af..e6a9ee586dd088317e7e30f5d471a270f9784f6a 100644 (file)
@@ -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)