sanitize csv export
This commit is contained in:
@@ -111,7 +111,7 @@ class Csv implements Processor
|
||||
$item = Json::encode($item);
|
||||
}
|
||||
|
||||
$preparedRow[] = $item;
|
||||
$preparedRow[] = $this->sanitizeCell($item);
|
||||
}
|
||||
|
||||
return $preparedRow;
|
||||
@@ -140,4 +140,25 @@ class Csv implements Processor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
* @return mixed
|
||||
*/
|
||||
private function sanitizeCell($value)
|
||||
{
|
||||
if (!is_string($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if ($value === '') {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (in_array($value[0], ['+', '-', '@', '='])) {
|
||||
return "'" . $value;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user