Merge pull request #16090 from nextcloud/backport/16021/stable15

[stable15] Fall back to black for non-color values
This commit is contained in:
Roeland Jago Douma 2019-06-26 13:42:17 +02:00 committed by GitHub
commit 8d6625f5e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 0 deletions

View File

@ -111,6 +111,7 @@ class SvgController extends Controller {
*
* @param string $path
* @param string $color
* @param string $fileName
* @return DataDisplayResponse|NotFoundResponse
*/
private function getSvg(string $path, string $color, string $fileName) {

View File

@ -179,6 +179,11 @@ class IconsCacher {
* @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);