Skip to content

Commit

Permalink
Removed unnecessary variables (sonata-project#429)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Wentzell committed Jan 6, 2021
1 parent ada9b89 commit 831712a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/Writer/CsvWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions src/Writer/XlsWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,12 @@ public function write(array $data): void

fwrite($this->file, '<tr>');
// prevent xls injection
$patterns = ['/^=/', '/^\+/', '/^-/', '/^@/'];
$replace = ['!=', '!+', '!-', '!@'];
foreach ($data as $value) {
fwrite($this->file, sprintf('<td>%s</td>', preg_replace($patterns, $replace, $value)));
fwrite($this->file, sprintf('<td>%s</td>', preg_replace(
['/^=/', '/^\+/', '/^-/', '/^@/'],
['\'=', '\'+', '\'-', '\'@'],
$value
)));
}
fwrite($this->file, '</tr>');

Expand Down

0 comments on commit 831712a

Please sign in to comment.