tedious / JShrink

Javascript Minifier built in PHP
http://www.tedivm.com
BSD 3-Clause "New" or "Revised" License
747 stars 152 forks source link

Unclosed regex pattern at position: 4715 #135

Open CalzaFino opened 1 year ago

CalzaFino commented 1 year ago

Just updated to the newest version (1.6.7) and I am getting errors during static content deployment.

The Magento 2.4.6-p1 store with php 8.1 is showing the error:

Error happened during deploy process: Unclosed regex pattern at position: 4715

emirajbbd commented 1 year ago

RuntimeException: Unclosed regex pattern at position: 4543 in /vendor/tedivm/jshrink/src/JShrink/Minifier.php:639

Downgrading tedivm/jshrink (v1.6.7 => v1.6.6) fixed the issue

eBusinessAtlantique commented 1 year ago

Thanks for the hint @emirajbbd
It happens to me too. That is a shame that a small module from Magento 2 can stop the whole Magento. I understand people saying that Magento is heavy and unstable...

boseasha commented 1 year ago

@emirajbbd Downgrading to v1.6.6 doesnot fix the issue. I am having 2.4.6 version in PHP 8.2 in production mode with minify js enabled See error RuntimeException: Unclosed regex pattern at position: 169201 in vendor/tedivm/jshrink/src/JShrink/Minifier.php:639

tedivm commented 1 year ago

I've reverted the release- 1.6.8 matches 1.6.6.

If possible can someone share the code that actually triggered the bug?

eBusinessAtlantique commented 1 year ago

My log :

34 {main} {"exception":"[object] (RuntimeException(code: 0): Unclosed regex pattern at position: 755 at /home/XXX.fr/public_html/vendor/tedivm/jshrink/src/JShrink/Minifier.php:639)"} []

tedivm commented 1 year ago

The logs don't really help- what I need is the code that's being run through the minifier, so I can replicate the issue.

eBusinessAtlantique commented 1 year ago

I don't have that, this is the compiler of Magento 2 that sent this error.

xaevik commented 1 year ago

@tedivm @eBusinessAtlantique downgrading to 1.6.6 or upgrading to 1.6.8 does resolve issue with Magento 2 JS minification (we just ran into this).

hostep commented 1 year ago

@tedivm: with version 1.6.7 we get a lot of failures on a lot of javascript files in the Magento code base.

One of them (in case it helps) is this one: https://raw.githubusercontent.com/magento/magento2/2.4.6-p1/app/code/Magento/Catalog/view/base/web/js/price-utils.js

Quick test locally after downloading that price-utils.js file:

<?php

require_once('vendor/autoload.php');

\JShrink\Minifier::minify(
    file_get_contents('/path/to/price-utils.js')
);

Running this results in:

PHP Fatal error:  Uncaught RuntimeException: Unclosed regex pattern at position: 4894 in JShrink/src/JShrink/Minifier.php:639
Stack trace:
#0 JShrink/src/JShrink/Minifier.php(298): JShrink\Minifier->saveRegex()
#1 JShrink/src/JShrink/Minifier.php(162): JShrink\Minifier->loop()
#2 JShrink/src/JShrink/Minifier.php(137): JShrink\Minifier->minifyToString('/**\n * Copyrigh...', Array)
#3 JShrink/test.php(5): JShrink\Minifier::minify('/**\n * Copyrigh...')
#4 {main}
  thrown in JShrink/src/JShrink/Minifier.php on line 639

Update: if you need more examples that fail:

JDavidVR commented 5 months ago

facing same issue when adding Alpine.js ( i get the file from: https://unpkg.com/alpinejs@3.13.5/dist/cdn.min.js )

it has issues with this section:

{message:"No error message given."},{el:t,expression:r}),console.warn(`Alpine Expression Error: ${e.message}

${r?'Expression: "'+r+`"

`:""}`,t),setTimeout(()=>{throw e},0)}var Ie=!0;function ke(e)

a them fix for me, was to change it to:

{message:"No error message given."},{el:t,expression:r}),console.warn(`Alpine Expression Error: ${e.message}

${r?'Expression: "'+r+`"`:""}`,t),setTimeout(()=>{throw e},0)}var Ie=!0;function ke(e)