diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-18 01:57:02 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-18 01:57:02 +0900 |
| commit | fed0a6e7ac361af9b963c1f62411b1a85478230c (patch) | |
| tree | 5cde64a24845c761890fbcbe05e0d702f1ec8df7 /crates/shirabe/src/config.rs | |
| parent | e093b2be1c333e67c96aebb0a5291bea9ae3d6db (diff) | |
| download | php-shirabe-fed0a6e7ac361af9b963c1f62411b1a85478230c.tar.gz php-shirabe-fed0a6e7ac361af9b963c1f62411b1a85478230c.tar.zst php-shirabe-fed0a6e7ac361af9b963c1f62411b1a85478230c.zip | |
refactor(preg): add preg_is_match for existence-only call sites
The capture groups were discarded at 162 of the preg_match call sites,
which only tested the Option. They now call preg_is_match, which lets the
regex engine skip capture tracking.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/config.rs')
| -rw-r--r-- | crates/shirabe/src/config.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/crates/shirabe/src/config.rs b/crates/shirabe/src/config.rs index 7e37a544..d1f34477 100644 --- a/crates/shirabe/src/config.rs +++ b/crates/shirabe/src/config.rs @@ -11,8 +11,9 @@ use indexmap::IndexMap; use shirabe_php_shim::{ E_USER_DEPRECATED, PhpMixed, PregMatches, RuntimeException, array_key_exists, array_merge, array_search_mixed, array_unique, empty, filter_var_url, implode, in_array_loose, - in_array_strict, intval, is_array, is_string, parse_url, php_regex, php_to_string, preg_match, - preg_replace_callback, rtrim, strtolower, strtoupper, strtr, substr, trigger_error, + in_array_strict, intval, is_array, is_string, parse_url, php_regex, php_to_string, + preg_is_match, preg_match, preg_replace_callback, rtrim, strtolower, strtoupper, strtr, substr, + trigger_error, }; use crate::advisory::Auditor; @@ -481,11 +482,10 @@ impl Config { .unwrap_or("") .to_string(); if is_composer - && preg_match( + && preg_is_match( php_regex!(r"{^https?://(?:[a-z0-9-.]+\.)?packagist.org(/|$)}"), &repo_url, ) - .is_some() { self.disable_repo_by_name("packagist.org"); } @@ -971,7 +971,7 @@ impl Config { /// /// Since the dirs might not exist yet we can not call realpath or it will fail. fn realpath(&self, path: &str) -> String { - if preg_match(php_regex!(r"{^(?:/|[a-z]:|[a-z0-9.]+://|\\\\\\\\)}i"), path).is_some() { + if preg_is_match(php_regex!(r"{^(?:/|[a-z]:|[a-z0-9.]+://|\\\\\\\\)}i"), path) { return path.to_string(); } @@ -1013,7 +1013,7 @@ impl Config { repo_options: &IndexMap<String, PhpMixed>, ) -> anyhow::Result<()> { // Return right away if the URL is malformed or custom (see issue #5173), but only for non-HTTP(S) URLs - if !filter_var_url(url) && preg_match(php_regex!(r"{^https?://}"), url).is_none() { + if !filter_var_url(url) && !preg_is_match(php_regex!(r"{^https?://}"), url) { return Ok(()); } |
