PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Structures » Structures_DataGrid » Bug #7606

DataGrid Renderer CSV

Details

Submitted2006-05-11 16:27 UTC
Fromamarie at clever-age dot com
Assignedwiesemann
StatusClosed
PackageStructures_DataGrid
PHP Version5.1.4
OSN/A
Roadmaps(Not assigned)

Comments

[2006-05-11 16:27 UTC] amarie at clever-age dot com

Description:
------------
1) When you change the delimiter to ";", the renderer don't put quotes if there are a ";" in the data.

2) When you put "setUseQuotes()" at true, the data are lost.

Test script:
---------------
Old code in the file Structures/DataGrid/Renderer/CSV.php at line 166 :
if ($this->useQuotes) {
$content = '"' . str_replace('"', '""', $content) . '"';
} else {
if (strstr($content, '"')) {
$content = '"' . str_replace('"', '""', $content) . '"';
} elseif (strstr($content, ',')) {
$content = '"' . $content . '"';
}
$csv .= $content;
}

FIX :
if ($this->useQuotes) {
$content = '"' . str_replace('"', '""', $content) . '"';
} else {
if (strstr($content, '"')) {
$content = '"' . str_replace('"', '""', $content) . '"';
} elseif (strstr($content, <b>$this->delimiter</b>)) {
$content = '"' . $content . '"';
}
}
<b>$csv .= $content;</b>

Actual result:
--------------
CSV result for bug 1 :
$renderer =& $datagrid->getRenderer();
$renderer->setDelimiter(';');
$datagrid->render();

result :
line 1; data whithout quotes; data; data
line 2; data whith quotes; da;ta; da;ta

insted of :
line 1; data whithout quotes; data; data
line 2; data whith quotes; "da;ta"; "da;ta"

CSV result for bug 2 :
$renderer =& $datagrid->getRenderer();
$renderer->setDelimiter(';');
$renderer->setUseQuotes(true);
$datagrid->render();

result :
; ; ;
; ; ;
insted of :
"line 1"; "data whithout quotes"; "data"; "data"
"line 2"; "data whith quotes"; "da;ta"; "da;ta"