Skip to content

Commit

Permalink
Fall back to black for non-color values
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Jun 20, 2019
1 parent 4ff3978 commit 05381f0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/Controller/SvgController.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public function getSvgFromApp(string $app, string $fileName, string $color = 'ff
*
* @param string $path
* @param string $color
* @param string $fileName
* @return DataDisplayResponse|NotFoundResponse
*/
private function getSvg(string $path, string $color, string $fileName) {
Expand Down
5 changes: 5 additions & 0 deletions lib/private/Template/IconsCacher.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ private function parseUrl($url): array {
* @return 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)
$fillRe = '/<((circle|rect|path)((?!fill)[a-z0-9 =".\-#():;,])+)\/>/mi';
$svg = preg_replace($fillRe, '<$1 fill="#' . $color . '"/>', $svg);
Expand Down

0 comments on commit 05381f0

Please sign in to comment.