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

btemperli created an issue. See original summary.

btemperli’s picture

vvvi’s picture

Status: Active » Reviewed & tested by the community

I also got this error. The patch works good. Thanks.

Status: Reviewed & tested by the community » Needs work
thalles’s picture

Status: Needs work » Needs review
StatusFileSize
new598 bytes

Follow a patch

Status: Needs review » Needs work
thalles’s picture

Version: 8.x-3.x-dev » 8.x-4.x-dev

  • thalles committed 8945434 on 8.x-4.x
    Issue #3021180 by btemperli, thalles: preg_replace_callback: Unknown...
thalles’s picture

Status: Needs work » Fixed

Thanks @all!

thalles’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.