JsOptimizer preg_replace gives null as return

Created on 6 August 2018, over 6 years ago
Updated 21 August 2024, 3 months ago

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

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Asset library 

Last updated about 17 hours ago

No maintainer
Created by

🇳🇱Netherlands lennard westerveld Dordrecht, Netherlands

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024