Skip to content

Commit ac1aea9

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

22 files changed

Lines changed: 639 additions & 48 deletions

NEWS

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

336+
- PCRE:
337+
. Added the PREG_THROW_ON_ERROR flag to make the preg_*() functions throw a
338+
\PregException on any PCRE error. (aldemeery)
339+
336340
- PDO_DBLIB:
337341
. Added dblib_handle_check_liveness handler. (freddy77)
338342

UPGRADING

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,20 @@ PHP 8.6 UPGRADE NOTES
289289
. Added TLS external PSK support for streams with new strem context options:
290290
psk_client_cb and psk_server_cb. This allows setting and receiving PSK.
291291

292+
- PCRE:
293+
. Added the PREG_THROW_ON_ERROR flag. When passed to a preg_*() function that
294+
accepts a $flags argument, any PCRE error reported by preg_last_error()
295+
throws a \PregException instead of emitting a warning or returning
296+
false/null. The exception's code and message are exactly what
297+
preg_last_error() and preg_last_error_msg() report for the same call: the
298+
flag changes how an error is delivered, not the error itself. This covers
299+
both compilation errors (such as a malformed pattern) and execution errors
300+
(such as an exhausted backtrack limit or malformed UTF-8 input under the /u
301+
modifier). preg_replace() and preg_filter() gained a $flags parameter to
302+
accept it. As on the non-flag path, by-reference outputs (the $matches and
303+
$count arguments) may already have been written when the \PregException is
304+
thrown, so a catch block should not assume they are left untouched.
305+
292306
- Phar:
293307
. Overriding the getMTime() and getPathname() methods of SplFileInfo now
294308
influences the result of the phar buildFrom family of functions.
@@ -373,6 +387,10 @@ PHP 8.6 UPGRADE NOTES
373387
. Output of openssl_x509_parse() contains criticalExtensions listing all
374388
critical certificate extensions.
375389

390+
- PCRE:
391+
. preg_replace() and preg_filter() now accept an optional $flags argument
392+
(for PREG_THROW_ON_ERROR).
393+
376394
- PDO_DBLIB:
377395
. When using persistent connections, there is now a liveness check in the
378396
constructor.
@@ -443,6 +461,9 @@ PHP 8.6 UPGRADE NOTES
443461
RFC: https://wiki.php.net/rfc/tls_session_resumption
444462
. Openssl\Psk
445463

464+
- PCRE:
465+
. PregException
466+
446467
- Standard:
447468
. enum SortDirection
448469
RFC: https://wiki.php.net/rfc/sort_direction_enum
@@ -502,6 +523,9 @@ PHP 8.6 UPGRADE NOTES
502523
. CURL_SEEKFUNC_FAIL.
503524
. CURL_SEEKFUNC_CANTSEEK.
504525

526+
- PCRE:
527+
. PREG_THROW_ON_ERROR.
528+
505529
- Sockets:
506530
. TCP_USER_TIMEOUT (Linux only).
507531
. 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)