Skip to content

Commit 3671745

Browse files
committed
Add a PREG_THROW_ON_ERROR flag that makes the preg functions throw on error.
1 parent 6df1311 commit 3671745

22 files changed

Lines changed: 579 additions & 47 deletions

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,10 @@ PHP NEWS
789789
. pcntl_exec() now throws a ValueError if the $args array is not a list
790790
array. (Weilin Du)
791791

792+
- PCRE:
793+
. Added the PREG_THROW_ON_ERROR flag to make the preg_*() functions throw a
794+
\PregException on any PCRE error. (aldemeery)
795+
792796
- PDO_DBLIB:
793797
. Added dblib_handle_check_liveness handler. (freddy77)
794798

UPGRADING

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,20 @@ PHP 8.6 UPGRADE NOTES
427427
outcome is reported as 'accepted', 'rejected' or 'not_sent' in the
428428
early_data key of the crypto stream_get_meta_data() array.
429429

430+
- PCRE:
431+
. Added the PREG_THROW_ON_ERROR flag. When passed to a preg_*() function that
432+
accepts a $flags argument, any PCRE error reported by preg_last_error()
433+
throws a \PregException instead of emitting a warning or returning
434+
false/null. The exception's code and message are exactly what
435+
preg_last_error() and preg_last_error_msg() report for the same call: the
436+
flag changes how an error is delivered, not the error itself. This covers
437+
both compilation errors (such as a malformed pattern) and execution errors
438+
(such as an exhausted backtrack limit or malformed UTF-8 input under the /u
439+
modifier). preg_replace() and preg_filter() gained a $flags parameter to
440+
accept it. As on the non-flag path, by-reference outputs (the $matches and
441+
$count arguments) may already have been written when the \PregException is
442+
thrown, so a catch block should not assume they are left untouched.
443+
430444
- PDO_PGSQL:
431445
. Added Pdo\Pgsql::ATTR_CHUNK_SIZE, the number of rows a statement fetches
432446
per chunk. A value of 1 or more enters the lazy fetch mode of
@@ -669,6 +683,10 @@ PHP 8.6 UPGRADE NOTES
669683
when OPENSSL_PKCS1_PSS_PADDING is used. It accepts an explicit length or
670684
one of the new OPENSSL_RSA_PSS_SALTLEN_* constants.
671685

686+
- PCRE:
687+
. preg_replace() and preg_filter() now accept an optional $flags argument
688+
(for PREG_THROW_ON_ERROR).
689+
672690
- PDO_DBLIB:
673691
. When using persistent connections, there is now a liveness check in the
674692
constructor.
@@ -782,6 +800,9 @@ PHP 8.6 UPGRADE NOTES
782800
RFC: https://wiki.php.net/rfc/tls_session_resumption
783801
. Openssl\Psk
784802

803+
- PCRE:
804+
. PregException
805+
785806
- SNMP:
786807
. enum: Snmp\Mib
787808
. enum: Snmp\OidOutput
@@ -856,6 +877,9 @@ PHP 8.6 UPGRADE NOTES
856877
. OPENSSL_RSA_PSS_SALTLEN_AUTO.
857878
. OPENSSL_RSA_PSS_SALTLEN_MAX.
858879

880+
- PCRE:
881+
. PREG_THROW_ON_ERROR.
882+
859883
- Sockets:
860884
. TCP_USER_TIMEOUT (Linux only).
861885
. AF_UNSPEC.

ext/fileinfo/libmagic/funcs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ file_replace(struct magic_set *ms, const char *pat, const char *rep)
663663

664664
opts |= PCRE2_MULTILINE;
665665
pattern = convert_libmagic_pattern(pat, strlen(pat), opts);
666-
pce = pcre_get_compiled_regex_cache_ex(pattern, 0);
666+
pce = pcre_get_compiled_regex_cache_ex(pattern, 0, 0);
667667
zend_string_release_ex(pattern, 0);
668668
if (pce == NULL) {
669669
rep_cnt = -1;

ext/fileinfo/libmagic/softmagic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ check_fmt(struct magic_set *ms, const char *fmt)
497497
return 0;
498498

499499
pattern = ZSTR_INIT_LITERAL("~%[-0-9\\.]*s~", 0);
500-
if ((pce = pcre_get_compiled_regex_cache_ex(pattern, 0)) == NULL) {
500+
if ((pce = pcre_get_compiled_regex_cache_ex(pattern, 0, 0)) == NULL) {
501501
rv = -1;
502502
} else {
503503
pcre2_code *re = php_pcre_pce_re(pce);

0 commit comments

Comments
 (0)