From 9d229c7f7ce6c09656c6384def295ba6de3afef0 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sun, 10 Feb 2008 04:09:12 +0000 Subject: [PATCH] Fixed Bug #42229 (fgetcsv() behaves differently for a file containing '\n' with php5 and php6) --- ext/standard/file.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/ext/standard/file.c b/ext/standard/file.c index e4a3ff640b..8872fc3a92 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -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: -- 2.50.1