diff --git a/src/Writer/CsvWriter.php b/src/Writer/CsvWriter.php index d97023f7..d0c72496 100644 --- a/src/Writer/CsvWriter.php +++ b/src/Writer/CsvWriter.php @@ -138,10 +138,12 @@ public function write(array $data): void } // prevent csv injection - $patterns = ['/^=/', '/^\+/', '/^-/', '/^@/']; - $replace = ['!=', '!+', '!-', '!@']; foreach ($data as $key => $value) { - $data[$key] = preg_replace($patterns, $replace, $value); + $data[$key] = preg_replace( + ['/^=/', '/^\+/', '/^-/', '/^@/'], + ['\'=', '\'+', '\'-', '\'@'], + $value + ); } $result = @fputcsv($this->file, $data, $this->delimiter, $this->enclosure, $this->escape); diff --git a/src/Writer/XlsWriter.php b/src/Writer/XlsWriter.php index 43ad5a2c..4a0ab464 100644 --- a/src/Writer/XlsWriter.php +++ b/src/Writer/XlsWriter.php @@ -79,10 +79,12 @@ public function write(array $data): void fwrite($this->file, ''); // prevent xls injection - $patterns = ['/^=/', '/^\+/', '/^-/', '/^@/']; - $replace = ['!=', '!+', '!-', '!@']; foreach ($data as $value) { - fwrite($this->file, sprintf('%s', preg_replace($patterns, $replace, $value))); + fwrite($this->file, sprintf('%s', preg_replace( + ['/^=/', '/^\+/', '/^-/', '/^@/'], + ['\'=', '\'+', '\'-', '\'@'], + $value + ))); } fwrite($this->file, '');