Fix regex detection when a character class contains unescaped forward slash#148
Merged
Merged
Conversation
Contributor
Author
|
Hi @tedivm Could you please review this fix? I believe it resolves the issue. Thank you for maintaining this library! |
Contributor
Author
|
Hi @tedivm, |
tedivm
approved these changes
Jul 28, 2025
Member
|
Thanks! |
Contributor
Author
|
Thank You, @tedivm. I appreciate your prompt attention and support. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The current logic is failing to properly detect the following regular expression (see):
resulting in
Root Cause
This is because the parser is stopping at the first unescaped forward slash which is located in the character class. However a character class can contain unescaped forward slash (see) and is a valid regular expression in Javascript.
Next it's parsing the rest of the regular expression as String starting from the string delimiter ` resulting in the next few lines not being minimized.
Solution
Added logic to ignore unescaped forward slash inside a character class
Issues
Related Pull Requests
Comment
I understand there had been an attempt to fix this issue but was reverted later due to regression issues caused by the fix. As I understand the regression issues were found in Magento according to this issue. I tested the solution with magento when JS minification is enabled and it worked fine.
The same sequence of commands failed with the previously proposed solution.