iliaa Sun Feb 23 22:15:54 2003 EDT Added files: (Branch: PHP_4_3) /php4/ext/standard/tests/file bug22382.phpt test2.csv
Modified files: /php4/ext/standard file.c Log: MFH Index: php4/ext/standard/file.c diff -u php4/ext/standard/file.c:1.279.2.10 php4/ext/standard/file.c:1.279.2.11 --- php4/ext/standard/file.c:1.279.2.10 Fri Feb 21 21:43:58 2003 +++ php4/ext/standard/file.c Sun Feb 23 22:15:53 2003 @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: file.c,v 1.279.2.10 2003/02/22 02:43:58 wez Exp $ */ +/* $Id: file.c,v 1.279.2.11 2003/02/24 03:15:53 iliaa Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ @@ -2210,6 +2210,21 @@ /* 2A. handle enclosure delimited field */ while (*bptr) { + /* we need to determine if the enclosure is 'real' or is it escaped */ + if (*(bptr - 1) == '\\') { + int escape_cnt = 0; + char *bptr_p = bptr - 2; + + while (bptr_p > buf && *bptr_p == '\\') { + escape_cnt++; + bptr_p--; + } + if (!(escape_cnt % 2)) { + goto normal_char; + continue; + } + } + if (*bptr == enclosure) { /* handle the enclosure */ if ( *(bptr+1) == enclosure) { @@ -2223,6 +2238,7 @@ break; /* .. from handling this field - resumes at 3. */ } } else { +normal_char: /* normal character */ *tptr++ = *bptr++; Index: php4/ext/standard/tests/file/bug22382.phpt +++ php4/ext/standard/tests/file/bug22382.phpt --TEST-- Bug #22382: fgetcvs does not handle escaped quotes correctly --POST-- --GET-- --FILE-- <?php $fp = fopen(dirname(__FILE__)."/test2.csv", "r"); while(($line = fgetcsv($fp, 1024))) { var_dump($line); } fclose($fp); ?> --EXPECT-- array(6) { [0]=> string(3) "One" [1]=> string(7) "\"Two\"" [2]=> string(7) "Three\"" [3]=> string(4) "Four" [4]=> string(2) "\\" [5]=> string(28) "\\\\\\\\\\\\\\\\\\\\\\\"\\\\" } Index: php4/ext/standard/tests/file/test2.csv +++ php4/ext/standard/tests/file/test2.csv "One","\"Two\"","Three\"","Four","\\","\\\\\\\\\\\\\\\\\\\\\\\"\\\\" -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php