From: Ilia Alshanetsky Date: Sun, 24 May 2009 16:02:22 +0000 (+0000) Subject: Improve fix for bug #48313 X-Git-Tag: php-5.2.10RC1~23 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0008c005b9717783dbab73fb96686b4f350617d6;p=php Improve fix for bug #48313 --- diff --git a/ext/standard/file.c b/ext/standard/file.c index 21870c3d32..c7fc97ce15 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -2139,6 +2139,7 @@ PHPAPI void php_fgetcsv(php_stream *stream, char delimiter, char enclosure, size size_t temp_len, line_end_len; int inc_len; + zend_bool first_field = 1; /* initialize internal state */ php_mblen(NULL, 0); @@ -2190,6 +2191,11 @@ PHPAPI void php_fgetcsv(php_stream *stream, char delimiter, char enclosure, size } 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; @@ -2384,12 +2390,8 @@ PHPAPI void php_fgetcsv(php_stream *stream, char delimiter, char enclosure, size } /* 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/http_fopen_wrapper.c b/ext/standard/http_fopen_wrapper.c index 2d75f0ed52..9a9b7ae9c9 100644 --- a/ext/standard/http_fopen_wrapper.c +++ b/ext/standard/http_fopen_wrapper.c @@ -553,7 +553,8 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path, response_code = 0; } /* when we request only the header, don't fail even on error codes */ - if (options & STREAM_ONLY_GET_HEADERS) { + if ((options & STREAM_ONLY_GET_HEADERS) || + (context && php_stream_context_get_option(context, "http", "ignore_errors", &tmpzval) == SUCCESS && zend_is_true(*tmpzval)) ) { reqok = 1; } switch(response_code) { 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)