Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128768 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id 159FE1A00BC for ; Thu, 2 Oct 2025 11:04:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1759402991; bh=FeMaBGbMCUaM6Gy4ERTfAbs1Q4deXX7lJNT8F+IKgvE=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=i62ldVo94l1yhZgE7DYhGa/AYgCiz/iidlgoy/wAsVK92iYYC8l41uyG70xJZaU2M ojg581KitxBQq4Y5kvPCGkc3SAJA3AgPyXUe5xY22jrIU/53wjAli+3jhflLkBEaId j/atJ/DI6jr7sQpgnt4HZC81D/TiR2jLLYBQxIKNSa7ro+jYwKjH7C1JSMAe4vrurU +moNPJmhw3L35/nrKO2wQcboNdxEo9EwOVPJB6iL99o9Sx5J0/MF/zSWS4OkCeBAhL 0WRUb2jnAZKY+hz3jdlhqaE4h7lR74pDoc8PXOYct9E5AMHdrs4z7MeXxil/Cz7rUF 7v9cOXe8YfqRQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5CED518006D for ; Thu, 2 Oct 2025 11:03:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from forward500a.mail.yandex.net (forward500a.mail.yandex.net [178.154.239.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 2 Oct 2025 11:03:08 +0000 (UTC) Received: from mail-nwsmtp-smtp-production-main-55.vla.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-55.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:582e:0:640:200:0]) by forward500a.mail.yandex.net (Yandex) with ESMTPS id 5F79181755 for ; Thu, 02 Oct 2025 14:04:24 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-55.vla.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id N4eO2nAMoW20-wAP7SiY3; Thu, 02 Oct 2025 14:04:24 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=php.watch; s=mail; t=1759403064; bh=FeMaBGbMCUaM6Gy4ERTfAbs1Q4deXX7lJNT8F+IKgvE=; h=To:Subject:Message-ID:References:Date:From:Cc:In-Reply-To; b=o5ZEDvZdYJGQ7m5Pgfdi2drYTO9d6wzHH4UmHLh9RnPTIbl9G37AzJeFg7keP2Ml2 GdRHTNep52CeyiC3WZngxAwbaqQ+mjV5A0JwILimgLZGqbeSdLxJGDfJCp8sHUNQrs bg3AmAm3Jhzq+iNq3vrHbMEW5xVpuX4hXkvl5Dt4= Authentication-Results: mail-nwsmtp-smtp-production-main-55.vla.yp-c.yandex.net; dkim=pass header.i=@php.watch Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-637e2b86240so1087579a12.0 for ; Thu, 02 Oct 2025 04:04:23 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCWqoZ7SLQgwTt4d1FbdKJOqMdZ8AB+OInF7ZIfqFZyQ+e79o4tqUMdBuoDfd07hDPvRcUrEphyVxE8=@lists.php.net X-Gm-Message-State: AOJu0YyLafeAmHc/cT0uLolADVd5yZCvm1b7i7HbF6oweDr09CRYHChc JrzUB6Pj6aANFjuAlthpWevvvRq4Z39al72gccidTVxnpNqTSwCCzCTZRzt4RjnDPMPDREpmho2 PGXY8Nz78+EnwWdvN9CSi9GmXMzMO5X0= X-Google-Smtp-Source: AGHT+IGcRrQr5UxOXoQt4EDj3lSCj9xJgITPIn/eq+3pp7AeP3/lUtUI8OmH+14qwzDyNNJ+0X93vgUP1X5F8nSQVIE= X-Received: by 2002:a17:907:1c90:b0:b43:b740:b35d with SMTP id a640c23a62f3a-b46e9765d7cmr871342266b.33.1759403063098; Thu, 02 Oct 2025 04:04:23 -0700 (PDT) Precedence: list list-help: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: <68DD64BE.5080308@adviesenzo.nl> In-Reply-To: Date: Thu, 2 Oct 2025 18:03:55 +0700 X-Gmail-Original-Message-ID: X-Gm-Features: AS18NWBSzRbLVELxZzJTKkS5gincV3sY_AZmsDdqrxJNTHopRWtUvUwE1S0SwRQ Message-ID: Subject: Re: [PHP-DEV] [DISCUSSION] Validating regex pattern To: Alexandre Daubois Cc: Juliette Reinders Folmer , internals@lists.php.net Content-Type: text/plain; charset="UTF-8" From: ayesh@php.watch (Ayesh Karunaratne) > > > It also makes the `FILTER_VALIDATE_REGEX_PATTERN` flag highly ambiguous as it is unclear against which engine/dialect the regex would be validated. > > Indeed, the multi-engine "issue" makes it clear that it would be ambiguous. > > > Maybe the error code flags returned via `preg_last_error()` [4] should be made more specific to allow for detecting when a regex function failed due to an error in the regex. > > Maybe the extensions should get a "throw on invalid regex" option, either via an ini flag, a new function parameter or via an existing function like `mb_regex_set_options()`. > > I like the first solution, I like the second one even more. It would > be aligned with JSON_THROW_ON_ERROR. > I completely agree with this and the previous reply from Juliette. I'm familiar with the upstream PCRE2 library, and they have made several changes to the regex rules/syntax within the past couple years. Unless the validation is made within the same realm of the engine, it will have to be validated by the engine itself if we want the validation to be accurate to the rules supported by the engine. A `PREG_THROW_ON_ERROR` flag would be the best of both worlds: - Provides a nice safe-guard against potentially invalid regexps and surfaces them up as an exception. - Provides validation functionality with engine-provided error messages. - We do not need to keep up with the regex engines because validation is done by the engine. - Works similar to the `JSON_THROW_ON_ERROR` flag.