Skip to content

Commit

Permalink
Fixed exporting for < PHP 7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Oct 21, 2021
1 parent e45ce51 commit 034e2d7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,7 @@

### Fixed
- Fixed a PHP error that could occur when uploading assets on some environments.
- Fixed a PHP error that occurred when exporting elements on PHP 7.2 or 7.3. ([#9958](https://github.com/craftcms/cms/issues/9958))
- Fixed a JavaScript error that occurred in Safari. ([#9976](https://github.com/craftcms/cms/issues/9976))

## 3.7.17.1 - 2021-10-20
Expand Down
7 changes: 6 additions & 1 deletion src/web/CsvResponseFormatter.php
Expand Up @@ -85,6 +85,11 @@ public function format($response)

$suspectCharacters = ['=', '-', '+', '@'];

$escapeChar = $this->escapeChar;
if ($escapeChar === '' && PHP_VERSION_ID < 70400) {
$escapeChar = '\\';
}

foreach ($data as $row) {
foreach ($row as &$field) {
if (is_scalar($field)) {
Expand All @@ -100,7 +105,7 @@ public function format($response)
}
}
unset($field);
fputcsv($fp, $row, $this->delimiter, $this->enclosure, $this->escapeChar);
fputcsv($fp, $row, $this->delimiter, $this->enclosure, $escapeChar);
}

fclose($fp);
Expand Down

0 comments on commit 034e2d7

Please sign in to comment.