/* 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) {
break; /* .. from handling this field - resumes at 3. */
}
} else {
+normal_char:
/* normal character */
*tptr++ = *bptr++;
--- /dev/null
+--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) "\\\\\\\\\\\\\\\\\\\\\\\"\\\\"
+}
\ No newline at end of file