[turba] CSV EXPORT double quotes problem

Rong-en Fan rafan@infor.org
Wed, 31 Jul 2002 23:04:49 +0800


Hi all,

I'm using Horde 2.1 and Turba 1.1 on PHP 4.2.2, all settings are default
except something like sql db, user, password, etc.

The CSV exported from Turba has a little problem while there are double
quotes in it. The output will be something like ...,"\"",... , but
the CSV that generated by MS Excel 2000 / Outlook Express 6 and CSV file
format found from http://www.wotsit.org/download.asp?f=csv both say that
if any double quotes in the source data, the encapsulation in CSV should
be doubled up, i.e. " (source data) ==> ...,"""",... Also, if we import
the CSV file exported by Turba, Turba will interpret the fields incorrectly.
(Try it yourself :p)

The problem lays in horde/lib/Data.php, Line 113

    $export .= '"' . addslashes($cell) . '"';

addslashes($cell) exists since the initial version 1.1 of Data.php
I wonder why there is addslashes(), my own patch is

-                    $export .= '"' . addslashes($cell) . '"';
+                    $cell = preg_replace ("/\"/", "\"\"", $cell);
+                    $export .= '"' . $cell . '"';

Finally, is there any strong reason that we have to use addslases($cell),
instead just leave $cell along and doubled double quotes up?

Regards,
Rong-en Fan