Skip to content

Commit

Permalink
Fix Twig svg_image() issue with classes applied to all elements #3068
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Dec 10, 2020
1 parent bc22c8d commit 1c63f4b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
## mm/dd/2020

1. [](#improved)
* Allow all CSS and JS via `robots.txt` [#2006](https://github.com/getgrav/grav/issues/2006) [#3067](https://github.com/getgrav/grav/issues/3067)
* Allow all CSS and JS via `robots.txt` [#2006](https://github.com/getgrav/grav/issues/2006) [#3067](https://github.com/getgrav/grav/issues/3067)
1. [](#bugfix)
* Fixed `pages` field escaping issues, needs admin update, too [admin#1990](https://github.com/getgrav/grav-plugin-admin/issues/1990)
* Fix `svg-image` issue with classes applied to all elements [#3068](https://github.com/getgrav/grav/issues/3068)

# v1.6.30
## 12/03/2020
Expand Down
3 changes: 2 additions & 1 deletion system/src/Grav/Common/Twig/TwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -1477,12 +1477,13 @@ public static function svgImageFunction($path, $classes)
$matched = false;

//Look for existing class
$svg = preg_replace_callback('/^<svg.*?(class=\"(.*?)").*>/', function($matches) use ($classes, &$matched) {
$svg = preg_replace_callback('/^<svg[^>]*(class=\")([^"]*)(\")[^>]*>/', function($matches) use ($classes, &$matched) {
if (isset($matches[2])) {
$new_classes = $matches[2] . $classes;
$matched = true;
return str_replace($matches[1], "class=\"$new_classes\"", $matches[0]);
}
return $matches[0];
}, $svg
);

Expand Down

0 comments on commit 1c63f4b

Please sign in to comment.