iliaa Thu Dec 5 15:01:19 2002 EDT Modified files: /php4/ext/standard file.c /php4/ext/standard/tests/file bug12556.phpt Log: Fixed bug #12556, updated the test for this bug. Index: php4/ext/standard/file.c diff -u php4/ext/standard/file.c:1.281 php4/ext/standard/file.c:1.282 --- php4/ext/standard/file.c:1.281 Sat Nov 30 14:12:48 2002 +++ php4/ext/standard/file.c Thu Dec 5 15:01:18 2002 @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: file.c,v 1.281 2002/11/30 19:12:48 iliaa Exp $ */ +/* $Id: file.c,v 1.282 2002/12/05 20:01:18 iliaa Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ @@ -2109,7 +2109,7 @@ /* first section exactly as php_fgetss */ zval **fd, **bytes, **p_delim, **p_enclosure; - int len; + int len, temp_len; char *buf; php_stream *stream; @@ -2194,7 +2194,8 @@ /* reserve workspace for building each individual field */ - temp = emalloc(len); /* unlikely but possible! */ + temp_len = len; + temp = emalloc(temp_len + 1); /* unlikely but possible! */ tptr = temp; /* Initialize return array */ @@ -2209,7 +2210,7 @@ /* 2. Read field, leaving bptr pointing at start of next field */ if (enclosure && *bptr == enclosure) { bptr++; /* move on to first character in field */ - + /* 2A. handle enclosure delimited field */ while (*bptr) { if (*bptr == enclosure) { @@ -2236,6 +2237,13 @@ memset(buf, 0, len+1); if (php_stream_gets(stream, buf, len) == NULL) { + /* we've got an unterminated +enclosure, assign all the data + * from the start of the +enclosure to end of data to the last element + */ + if (temp_len > len) { + break; + } + efree(lineEnd); efree(temp); efree(buf); @@ -2243,6 +2251,8 @@ RETURN_FALSE; } + temp_len += len; + temp = erealloc(temp, temp_len+1); bptr = buf; tptr = buf + strlen(buf) -1; while (isspace((int) *tptr) && (*tptr!=delimiter) && (tptr > bptr)) Index: php4/ext/standard/tests/file/bug12556.phpt diff -u php4/ext/standard/tests/file/bug12556.phpt:1.1 php4/ext/standard/tests/file/bug12556.phpt:1.2 --- php4/ext/standard/tests/file/bug12556.phpt:1.1 Thu Dec 5 14:29:45 2002 +++ php4/ext/standard/tests/file/bug12556.phpt Thu Dec 5 15:01:19 2002 @@ -4,18 +4,46 @@ --GET-- --FILE-- <?php -$fp=fopen(dirname(__FILE__)."/test.csv", "r"); -while($line=fgetcsv($fp, 24)){ - print("Read 24 bytes\n"); +$fp = fopen(dirname(__FILE__)."/test.csv", "r"); +while($line = fgetcsv($fp, 24)) { + var_dump($line); } +fclose($fp); ?> --EXPECT-- -Read 24 bytes -Read 24 bytes -Read 24 bytes -Read 24 bytes -Read 24 bytes -Read 24 bytes -Read 24 bytes -Read 24 bytes -Read 24 bytes +array(4) { + [0]=> + string(1) "6" + [1]=> + string(1) "7" + [2]=> + string(1) "8" + [3]=> + string(5) "line1" +} +array(4) { + [0]=> + string(1) "1" + [1]=> + string(1) "2" + [2]=> + string(1) "3" + [3]=> + string(186) "line2 +2,4,5,line3 +2,4,5,line3 +2,4,5,line3 +2,4,5,line3 +2,4,5,line3 +2,4,5,line3 +2,4,5,line3 +2,4,5,line3 +2,4,5,line3 +2,4,5,line3 +2,4,5,line3 +2,4,5,line3 +2,4,5,line3 +2,4,5,line3 +2,4,5,line3 +" +}
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php