Fall back to black for non-color values
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
4ff3978a6d
commit
05381f00d2
|
@ -111,6 +111,7 @@ class SvgController extends Controller {
|
||||||
*
|
*
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @param string $color
|
* @param string $color
|
||||||
|
* @param string $fileName
|
||||||
* @return DataDisplayResponse|NotFoundResponse
|
* @return DataDisplayResponse|NotFoundResponse
|
||||||
*/
|
*/
|
||||||
private function getSvg(string $path, string $color, string $fileName) {
|
private function getSvg(string $path, string $color, string $fileName) {
|
||||||
|
|
|
@ -184,6 +184,11 @@ class IconsCacher {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function colorizeSvg($svg, $color): string {
|
public function colorizeSvg($svg, $color): string {
|
||||||
|
if (!preg_match('/^[0-9a-f]{3,6}$/i', $color)) {
|
||||||
|
// Prevent not-sane colors from being written into the SVG
|
||||||
|
$color = '000';
|
||||||
|
}
|
||||||
|
|
||||||
// add fill (fill is not present on black elements)
|
// add fill (fill is not present on black elements)
|
||||||
$fillRe = '/<((circle|rect|path)((?!fill)[a-z0-9 =".\-#():;,])+)\/>/mi';
|
$fillRe = '/<((circle|rect|path)((?!fill)[a-z0-9 =".\-#():;,])+)\/>/mi';
|
||||||
$svg = preg_replace($fillRe, '<$1 fill="#' . $color . '"/>', $svg);
|
$svg = preg_replace($fillRe, '<$1 fill="#' . $color . '"/>', $svg);
|
||||||
|
|
Loading…
Reference in New Issue