Skip to content

Commit

Permalink
Use EscapeFormula() in CSV export
Browse files Browse the repository at this point in the history
Signed-off-by: snipe <snipe@snipe.net>
  • Loading branch information
snipe committed Sep 30, 2022
1 parent 2fd197c commit bae200e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/Http/Controllers/ReportsController.php
Expand Up @@ -22,7 +22,7 @@
use Input;
use League\Csv\Reader;
use Symfony\Component\HttpFoundation\StreamedResponse;

use League\Csv\EscapeFormula;
/**
* This controller handles all actions related to Reports for
* the Snipe-IT Asset Management application.
Expand Down Expand Up @@ -666,6 +666,9 @@ public function postCustom(Request $request)
$executionTime = microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'];
\Log::debug('Walking results: '.$executionTime);
$count = 0;

$formatter = new EscapeFormula("`");

foreach ($assets as $asset) {
$count++;
$row = [];
Expand Down Expand Up @@ -855,7 +858,7 @@ public function postCustom(Request $request)
$row[] = $asset->$column_name;
}
}
fputcsv($handle, $row);
fputcsv($handle, $formatter->escapeRecord($row));
$executionTime = microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'];
\Log::debug('-- Record '.$count.' Asset ID:'.$asset->id.' in '.$executionTime);
}
Expand Down

0 comments on commit bae200e

Please sign in to comment.