Req #77521 [NEW]: Validate regexes

From: Date: Fri, 25 Jan 2019 15:53:30 +0000
Subject: Req #77521 [NEW]: Validate regexes
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-219206@lists.php.net to get a copy of this message
From: flip101 at gmail dot com Operating system: Ubuntu 18.04 PHP version: 7.3.1 Package: PCRE related Bug Type: Feature/Change Request Bug description:Validate regexes Description: ------------ At the moment there is poor support to validate a regex. Since the inception of PHP where it was mainly used for creating personal home pages it's been used in more domains. Therefor having the ability to validate regexes would be a useful thing. As far as i know regexes can be validated to the PCRE engine in the following way: 1. make a custom error handler for PHP warning 2. register customer error handler 3. call preg_match with invalid regex 4. unregister custom error handler. 5. throw exception (or another way of dealing with the error) The motivation that led me here is the following library and issue: https://hoa-project.net/En/Literature/Hack/Compiler.html#PP_language https://github.com/hoaproject/Compiler/issues/15 But i believe there will be other projects now and in the feature that would benefit from a change in PHP PCRE module. I propose the following changes that should be backwards compatible: 1. Add constant PREG_INVALID_PATTERN (representing int 7) to https://secure.php.net/manual/en/function.preg-last-error.php which gets set when a pattern is an invalid regex. 2. Add a bool preg_validate_pattern($string) function that only calls the PCRE2 compile function and checks for succesful compilation. Skipping the step of actually trying to match a subject which is usually done. Test script: --------------- <?php $invalid_pattern = '/(\d+/'; $dummy_subject = ''; preg_match($invalid_pattern, $dummy_subject); -- Edit bug report at https://bugs.php.net/bug.php?id=77521&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77521&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77521&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77521&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=77521&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=77521&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=77521&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=77521&r=needscript Try newer version: https://bugs.php.net/fix.php?id=77521&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=77521&r=support Expected behavior: https://bugs.php.net/fix.php?id=77521&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=77521&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=77521&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=77521&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77521&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=77521&r=dst IIS Stability: https://bugs.php.net/fix.php?id=77521&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=77521&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=77521&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=77521&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=77521&r=mysqlcfg

« previous php.bugs (#219206) next »