iliaa           Sun Feb 23 22:13:25 2003 EDT

  Added files:                 
    /php4/ext/standard/tests/file       bug22382.phpt test2.csv 

  Modified files:              
    /php4/ext/standard  file.c 
  Log:
  Fixed bug #22382 (fgetcsv did not handle \" correctly).
  
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.309 php4/ext/standard/file.c:1.310
--- php4/ext/standard/file.c:1.309      Sat Feb 22 15:35:22 2003
+++ php4/ext/standard/file.c    Sun Feb 23 22:13:25 2003
@@ -21,7 +21,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: file.c,v 1.309 2003/02/22 20:35:22 iliaa Exp $ */
+/* $Id: file.c,v 1.310 2003/02/24 03:13:25 iliaa Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -2558,6 +2558,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) {
@@ -2571,6 +2586,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

Reply via email to