SVG Sanitizer Enhanced
This commit is contained in:
parent
3141e28b01
commit
7bbf0c4bb5
|
|
@ -7,21 +7,42 @@ use enshrined\svgSanitize\Sanitizer as MainSanitizer;
|
||||||
|
|
||||||
trait Sanitizer
|
trait Sanitizer
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* List of mime types which needs to check.
|
||||||
|
*/
|
||||||
|
public $mimeTypes = [
|
||||||
|
'image/svg',
|
||||||
|
'image/svg+xml'
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sanitize SVG file.
|
* Sanitize SVG file.
|
||||||
*
|
*
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function sanitizeSVG($path)
|
public function sanitizeSVG($path, $mimeType)
|
||||||
{
|
{
|
||||||
/* sanitizer instance */
|
if ($this->checkMimeType($mimeType)) {
|
||||||
$sanitizer = new MainSanitizer();
|
/* sanitizer instance */
|
||||||
|
$sanitizer = new MainSanitizer();
|
||||||
|
|
||||||
/* grab svg file */
|
/* grab svg file */
|
||||||
$dirtySVG = Storage::get($path);
|
$dirtySVG = Storage::get($path);
|
||||||
|
|
||||||
/* save sanitized svg */
|
/* save sanitized svg */
|
||||||
Storage::put($path, $sanitizer->sanitize($dirtySVG));
|
Storage::put($path, $sanitizer->sanitize($dirtySVG));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sanitize SVG file.
|
||||||
|
*
|
||||||
|
* @param string $path
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function checkMimeType($mimeType)
|
||||||
|
{
|
||||||
|
return in_array($mimeType, $this->mimeTypes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -54,9 +54,7 @@ class SearchRepository extends Repository
|
||||||
{
|
{
|
||||||
$path = request()->file('image')->store('product-search');
|
$path = request()->file('image')->store('product-search');
|
||||||
|
|
||||||
if ($data['image']->getMimeType() === 'image/svg') {
|
$this->sanitizeSVG($path, $data['image']->getMimeType());
|
||||||
$this->sanitizeSVG($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Storage::url($path);
|
return Storage::url($path);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -158,9 +158,7 @@ class ConfigurationController extends Controller
|
||||||
$saveImage[substr($imageId, 6, 1)] = $path = request()->file($file)->store($dir);
|
$saveImage[substr($imageId, 6, 1)] = $path = request()->file($file)->store($dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($image->getMimeType() === 'image/svg') {
|
$this->sanitizeSVG($path, $image->getMimeType());
|
||||||
$this->sanitizeSVG($path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isset($advertisement[$index][$imageId]) && $advertisement[$index][$imageId] && !request()->hasFile($file)) {
|
if (isset($advertisement[$index][$imageId]) && $advertisement[$index][$imageId] && !request()->hasFile($file)) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue