Skip to content

Commit

Permalink
fix: regex correctly matches url() referenced assets
Browse files Browse the repository at this point in the history
Additionally, adjusted how greedy the regex is and added
links out to Regex101.com for easy future reference

This fix addresses the issue reported here:
getgrav#7
  • Loading branch information
bsheen committed Oct 9, 2017
1 parent a6bc4c1 commit 1f223b0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cdn.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ function ($matches) use ($blocks, $pullzone) {

// replacements for inline CSS url() style references
if ($config['inline_css_replace']) {
$regex = "/(url\()(?:" . $base . ")(.*?\.(?:" . $extensions . "))(.*;)/i";

// https://regex101.com/r/8zAnec/2 -> (url\([\'\"])(?:)(.*?\.(?:jpe?g|png|gif|ttf|otf|svg|woff|xml|js|css))(.*?\);)/i
// or with $base
// https://regex101.com/r/g0R6sj/2 -> (url\([\'\"])(?:http:\/\/github\.com)(.*?\.(?:jpe?g|png|gif|ttf|otf|svg|woff|xml|js|css))(.*?\);)/i
$regex = "/(url\([\'])(?:" . $base . ")(.*?\.(?:" . $extensions . "))(.*?\);)/i";

$this->grav->output = preg_replace_callback(
$regex,
Expand Down

0 comments on commit 1f223b0

Please sign in to comment.