From 54d48bb31f74991c28d7654242112928b9f03b0c Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Tue, 13 Sep 2011 12:44:13 +0000 Subject: [PATCH] Fixed Bug #55674 (fgetcsv & str_getcsv skip empty fields in some tab-separated records) which was introduced by r311543 --- ext/standard/file.c | 2 +- ext/standard/tests/strings/bug55674.phpt | 50 ++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 ext/standard/tests/strings/bug55674.phpt diff --git a/ext/standard/file.c b/ext/standard/file.c index ef5f215c36..e86b21c7a6 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -2051,7 +2051,7 @@ PHPAPI void php_fgetcsv(php_stream *stream, char delimiter, char enclosure, char inc_len = (bptr < limit ? (*bptr == '\0' ? 1: php_mblen(bptr, limit - bptr)): 0); if (inc_len == 1) { char *tmp = bptr; - while (isspace((int)*(unsigned char *)tmp)) { + while ((*tmp != delimiter) && isspace((int)*(unsigned char *)tmp)) { tmp++; } if (*tmp == enclosure) { diff --git a/ext/standard/tests/strings/bug55674.phpt b/ext/standard/tests/strings/bug55674.phpt new file mode 100644 index 0000000000..72ece642a7 --- /dev/null +++ b/ext/standard/tests/strings/bug55674.phpt @@ -0,0 +1,50 @@ +--TEST-- +Bug #55674 (fgetcsv & str_getcsv skip empty fields in some tab-separated records) +--FILE-- + +--EXPECT-- +array(3) { + [0]=> + string(1) "0" + [1]=> + string(0) "" + [2]=> + string(1) "2" +} +array(3) { + [0]=> + string(1) "0" + [1]=> + string(1) " " + [2]=> + string(1) "2" +} +array(5) { + [0]=> + string(0) "" + [1]=> + string(0) "" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(0) "" +} +array(5) { + [0]=> + string(1) " " + [1]=> + string(2) " " + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(1) " " +} -- 2.40.0