Quoting is only needed when separators appear in text

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
This commit is contained in:
Kamil Tekiela 2025-11-21 17:41:10 +00:00
parent 233dc54ce8
commit 78dc2d1252

View File

@ -22,8 +22,9 @@ use PhpMyAdmin\Properties\Plugins\ExportPluginProperties;
use function __;
use function implode;
use function is_string;
use function mb_strtolower;
use function str_contains;
use function str_replace;
use function strtolower;
/**
* Handles the export for the CSV format
@ -112,7 +113,7 @@ class ExportCsv extends ExportPlugin
public function exportHeader(): bool
{
// Here we just prepare some values for export
if ($this->terminated === '' || mb_strtolower($this->terminated) === 'auto') {
if ($this->terminated === '' || strtolower($this->terminated) === 'auto') {
$this->terminated = "\n";
} else {
$this->terminated = str_replace(
@ -193,7 +194,13 @@ class ExportCsv extends ExportPlugin
foreach ($result->getFieldNames() as $colAs) {
$colAs = $this->getColumnAlias($aliases, $db, $table, $colAs);
if ($this->enclosed === '') {
if (
$this->enclosed === ''
|| (! str_contains($colAs, $this->separator)
&& ! str_contains($colAs, $this->enclosed)
&& ! str_contains($colAs, $this->terminated)
)
) {
$insertFields[] = $colAs;
} else {
$insertFields[] = $this->enclosed
@ -224,7 +231,13 @@ class ExportCsv extends ExportPlugin
);
}
if ($this->enclosed === '') {
if (
$this->enclosed === ''
|| (! str_contains($field, $this->separator)
&& ! str_contains($field, $this->enclosed)
&& ! str_contains($field, $this->terminated)
)
) {
$insertValues[] = $field;
} elseif ($this->escaped !== $this->enclosed) {
// also double the escape string if found in the data