Problem
I got the following warning this morning: preg_replace_callback(): Unknown modifier 'c'.
This happens in the file advagg/advagg_mod/src/Asset/DeferCss.php on line 72.
// Put JS inline if configured.
if ($this->deferMethod === 0) {
$path = drupal_get_path('module', 'advagg_mod') . '/js/loadCSS.js';
if (!strpos($content, $path)) {
$path = Crypt::hashBase64($path . $this->counter);
}
$pattern = "/<script src=['\"]\/(.*{$path}.*)\?.*['\"]>/";
$content = preg_replace_callback($pattern, [$this, 'inlineScript'], $content);
}
The result is, that $content results in null and the website gets no content (=whitescreen).
Proposed resolution
In my case, the multiple / in the $path breaks the preg_replace_callback. Problem is - in my opinion - that the slashes are not escaped.
I fixed it by adding 2 new lines:
// Put JS inline if configured.
if ($this->deferMethod === 0) {
$path = drupal_get_path('module', 'advagg_mod') . '/js/loadCSS.js';
if (!strpos($content, $path)) {
$path = Crypt::hashBase64($path . $this->counter);
+ } else {
+ $path = str_replace('/', '\/', $path);
}
$pattern = "/<script src=['\"]\/(.*{$path}.*)\?.*['\"]>/";
$content = preg_replace_callback($pattern, [$this, 'inlineScript'], $content);
}
Some details
I am not sure if it's just me with this problem. No problem if it is...
I have enabled these advagg-modules in a rarely empty drupal-project:
- advagg
- advagg_bundler
- advagg_css_minify
- advagg_js_minify
- advagg_mod
Comments
Comment #2
btemperli commentedComment #3
vvvi commentedI also got this error. The patch works good. Thanks.
Comment #5
thallesFollow a patch
Comment #7
thallesComment #9
thallesThanks @all!
Comment #10
thalles