Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 294747

JsOptimizer preg_replace gives null as return

$
0
0

Hi Drupal folks,

Couple of moths ago i came across a rare issue with the JsOptimizer the generated .JS file was empty.
After a few hours of debugging i came across the JsOptimizer::clean regex and saw that it gave NULL back as return.

$contents = preg_replace('/\/\/(#|@)\s(sourceURL|sourceMappingURL)=\s*(\S*?)\s*$/m', '', $contents);

No errors or notices in the logging what so ever, but i guess it was the "Backtracking limit" that the issue because there where a lot of javascript files that was optimised to one file. So i decide to rewrite the preg_replace to this one:

$contents = preg_replace('/\/\/(#|@)\s(sourceURL|sourceMappingURL)=\s*[^$\s]*\s*$/m', '', $contents);

And everything was working, i didn't have a test case with sourceURL|sourceMappingURL so thats needs to be tested if the preg_replace is working. I added the patch in this issue that we are using right now with success.

PHP Version: 7.1.x
Drupal version: 8.5.x


Viewing all articles
Browse latest Browse all 294747

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>