Skip to content

Commit a33a91c

Browse files
committed
Add a PREG_THROW_ON_ERROR flag that makes the preg functions throw on error.
1 parent 1053403 commit a33a91c

22 files changed

Lines changed: 579 additions & 47 deletions

NEWS

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

794+
- PCRE:
795+
. Added the PREG_THROW_ON_ERROR flag to make the preg_*() functions throw a
796+
\PregException on any PCRE error. (aldemeery)
797+
794798
- PDO_DBLIB:
795799
. Added dblib_handle_check_liveness handler. (freddy77)
796800

UPGRADING

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

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

693+
- PCRE:
694+
. preg_replace() and preg_filter() now accept an optional $flags argument
695+
(for PREG_THROW_ON_ERROR).
696+
679697
- PDO_DBLIB:
680698
. When using persistent connections, there is now a liveness check in the
681699
constructor.
@@ -789,6 +807,9 @@ PHP 8.6 UPGRADE NOTES
789807
RFC: https://wiki.php.net/rfc/tls_session_resumption
790808
. Openssl\Psk
791809

810+
- PCRE:
811+
. PregException
812+
792813
- SNMP:
793814
. enum: Snmp\Mib
794815
. enum: Snmp\OidOutput
@@ -863,6 +884,9 @@ PHP 8.6 UPGRADE NOTES
863884
. OPENSSL_RSA_PSS_SALTLEN_AUTO.
864885
. OPENSSL_RSA_PSS_SALTLEN_MAX.
865886

887+
- PCRE:
888+
. PREG_THROW_ON_ERROR.
889+
866890
- Sockets:
867891
. TCP_USER_TIMEOUT (Linux only).
868892
. 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)