summaryrefslogtreecommitdiff
path: root/program/lib/Roundcube/rcube_csv2vcard.php
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2013-01-07 15:06:09 +0100
committerAleksander Machniak <alec@alec.pl>2013-01-07 15:06:09 +0100
commit745d8697ba6ff7b35bda24d9c2319a9ed848152c (patch)
tree62b99720e43d39d7d59b2e951dd311383a1accfa /program/lib/Roundcube/rcube_csv2vcard.php
parent83f7077ec930952cdc9cfc8982b80cd4dad06b5f (diff)
Fix quoted data handling in CSV files (#1488899)
Diffstat (limited to 'program/lib/Roundcube/rcube_csv2vcard.php')
-rw-r--r--program/lib/Roundcube/rcube_csv2vcard.php37
1 files changed, 30 insertions, 7 deletions
diff --git a/program/lib/Roundcube/rcube_csv2vcard.php b/program/lib/Roundcube/rcube_csv2vcard.php
index 9c28a3b49..f94a7aac7 100644
--- a/program/lib/Roundcube/rcube_csv2vcard.php
+++ b/program/lib/Roundcube/rcube_csv2vcard.php
@@ -271,13 +271,7 @@ class rcube_csv2vcard
// Parse file
foreach (preg_split("/[\r\n]+/", $csv) as $i => $line) {
- $line = trim($line);
- if (empty($line)) {
- continue;
- }
-
- $elements = rcube_utils::explode_quoted_string(',', $line);
-
+ $elements = $this->parse_line($line);
if (empty($elements)) {
continue;
}
@@ -305,6 +299,35 @@ class rcube_csv2vcard
}
/**
+ * Parse CSV file line
+ */
+ protected function parse_line($line)
+ {
+ $line = trim($line);
+ if (empty($line)) {
+ return null;
+ }
+
+ $fields = rcube_utils::explode_quoted_string(',', $line);
+
+ // remove quotes if needed
+ if (!empty($fields)) {
+ foreach ($fields as $idx => $value) {
+ if (($len = strlen($value)) > 1 && $value[0] == '"' && $value[$len-1] == '"') {
+ // remove surrounding quotes
+ $value = substr($value, 1, -1);
+ // replace doubled quotes inside the string with single quote
+ $value = str_replace('""', '"', $value);
+
+ $fields[$idx] = $value;
+ }
+ }
+ }
+
+ return $fields;
+ }
+
+ /**
* Parse CSV header line, detect fields mapping
*/
protected function parse_header($elements)