]> granicus.if.org Git - php/commitdiff
Fixed Bug #42229 (fgetcsv() behaves differently for a file containing '\n' with php5...
authorFelipe Pena <felipe@php.net>
Sun, 10 Feb 2008 04:09:12 +0000 (04:09 +0000)
committerFelipe Pena <felipe@php.net>
Sun, 10 Feb 2008 04:09:12 +0000 (04:09 +0000)
ext/standard/file.c

index e4a3ff640bf6b36ad5c368c884582d2bb06184d9..8872fc3a92ebedf38766eb2e06ec74d41c1f9c93 100644 (file)
@@ -2359,6 +2359,11 @@ ready_state:
                                        if (p >= e) break;
                                        goto ready_state;
                                }
+                               
+                               /* Otherwise, starting a new field without enclosures */
+                               state = PHP_FGETCSV_FIELD_NO_ENC;
+                               field_start = p++;
+                               field_end = NULL;
 
                                /* Is it an escape character? */
                                if ((PHP_FGETCSV_BIN_CHECK(p, e, escape, escape_len) && escape != enclosure) ||
@@ -2368,15 +2373,9 @@ ready_state:
                                        /* Skip escape sequence and let next char be treated as literal
                                         * If enclosure is the same character as esacpe, it is considered as esacped
                                         * if it appears twice */
-                                       p += escape_len;
+                                       p += escape_len - 1;
                                        /* FALL THROUGH */
                                }
-
-                               /* Otherwise, starting a new field without enclosures */
-                               state = PHP_FGETCSV_FIELD_NO_ENC;
-                               field_start = p;
-                               field_end = NULL;
-                               p++;
                                break;
 
                        case PHP_FGETCSV_FIELD_WITH_ENC:
@@ -2568,6 +2567,11 @@ ready_state:
                                        if (p >= e) break;
                                        goto ready_state;
                                }
+                               
+                               /* Otherwise, starting a new field without enclosures */
+                               state = PHP_FGETCSV_FIELD_NO_ENC;
+                               field_start = p++;
+                               field_end = NULL;
 
                                /* Is it an escape character? */
                                if ((PHP_FGETCSV_UNI_CHECK(p, e, escape, escape_len) && escape != enclosure) ||
@@ -2575,17 +2579,11 @@ ready_state:
                                        PHP_FGETCSV_UNI_CHECK(p+1, e, escape, escape_len) && escape == enclosure)
                                ) {
                                        /* Skip escape sequence and let next char be treated as literal
-                                        * If enclosure is the same character as esacpe, it is considered as esacped
+                                        * If enclosure is the same character as escape, it is considered as escaped
                                         * if it appears twice */
-                                       p += escape_len;
+                                       p += escape_len - 1;
                                        /* FALL THROUGH */
                                }
-
-                               /* Otherwise, starting a new field without enclosures */
-                               state = PHP_FGETCSV_FIELD_NO_ENC;
-                               field_start = p;
-                               field_end = NULL;
-                               p++;
                                break;
 
                        case PHP_FGETCSV_FIELD_WITH_ENC: