From: Pierre Joye Date: Wed, 22 Nov 2006 12:56:26 +0000 (+0000) Subject: - #39538, fgetcsv can't handle starting newlines and trailing odd X-Git-Tag: RELEASE_1_0_0RC1~940 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=19abc4b507492669a5e3ff4a42043eab4515b9af;p=php - #39538, fgetcsv can't handle starting newlines and trailing odd number of backslashes (David Soria Parra, Pierre) --- diff --git a/ext/standard/file.c b/ext/standard/file.c index b2bed8b8a5..c933412c8c 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -2249,6 +2249,11 @@ PHPAPI void php_fgetcsv(php_stream *stream, /* {{{ */ memcpy(tptr, hunk_begin, bptr - hunk_begin); tptr += (bptr - hunk_begin); hunk_begin = bptr; + if (hunk_begin != line_end) { + memcpy(tptr, hunk_begin, bptr - hunk_begin); + tptr += (bptr - hunk_begin); + hunk_begin = bptr; + } /* add the embedded line end to the field */ memcpy(tptr, line_end, line_end_len); diff --git a/ext/standard/tests/file/bug39538.phpt b/ext/standard/tests/file/bug39538.phpt new file mode 100644 index 0000000000..16f15234fc --- /dev/null +++ b/ext/standard/tests/file/bug39538.phpt @@ -0,0 +1,40 @@ +--TEST-- +bug 39538 +--FILE-- + +this is an test + [1] => next data + [2] => p +arsed +) +Array +( + [0] => +this is an test + [1] => next data + [2] => p +arsed +) +Array +( + [0] => + +this is an test + [1] => next data + [2] => p + +arsed +)