Regex pattern is invalid: The /e modifier is no longer supported

Created on 13 September 2023, over 1 year ago

Problem/Motivation

Originating from 🐛 [META][pwa_service_worker] Refactor 'pwa_service_worker' implementations and flaws Needs work this is the issue just to remove the e modified which is definitely wrong and dangerous (eval()), see https://stackoverflow.com/questions/16986331/can-someone-explain-the-e-r... and should be removed.

We'll use 🐛 [META][pwa_service_worker] Refactor 'pwa_service_worker' implementations and flaws Needs work to fix other issues found

Original issue summary from there:

It is unclear how to properly fix the following PHPStan deprecation notice:

Regex pattern is invalid: The /e modifier is no longer supported, use preg_replace_callback instead in pattern:
#(/(\S*?\.\S*?))(\s|\;|\)|\]|\[|\{|\}|,|"|'|:|<|$|\.\s)#ie

Line 222 of "src/Controller/PWAController.php".

It recommends using "preg_replace_callback", but simply removing the "e" from "#ie" should already do the trick? If we used "preg_replace_callback", what would the callback function hold? Simply escaping the same characters "e" did before?

From the PHP docs concerning the deprecated "e" modifier:

When using the deprecated e modifier, this function escapes some characters (namely ', ", \ and NULL) in the strings that replace the backreferences. This is done to ensure that no syntax errors arise from backreference usage with either single or double quotes (e.g. 'strlen(\'$1\')+strlen("$2")'). Make sure you are aware of PHP's string syntax to know exactly how the interpreted string will look.

Steps to reproduce

Proposed resolution

Remove the e modified which was wrong since ever, as it seems.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇩🇪Germany Anybody Porta Westfalica

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

Comments & Activities

Production build 0.71.5 2024