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 | e093b2be1c333e67c96aebb0a5291bea9ae3d6db (patch) | |
| tree | 0743fad689f419959c3a898605e21485087884fa /crates/shirabe/src/config.rs | |
| parent | 050c56ef263d90d862ef565bc1762909110e02eb (diff) | |
| download | php-shirabe-e093b2be1c333e67c96aebb0a5291bea9ae3d6db.tar.gz php-shirabe-e093b2be1c333e67c96aebb0a5291bea9ae3d6db.tar.zst php-shirabe-e093b2be1c333e67c96aebb0a5291bea9ae3d6db.zip | |
refactor(preg): drop the offset argument from preg_match
Every call site but one passed offset 0. The remaining one, the UTF-8
chunking loop in Application, slices the subject instead: its pattern has
no anchor or lookaround, so matching a suffix is equivalent to starting
the search at that offset.
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 | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/crates/shirabe/src/config.rs b/crates/shirabe/src/config.rs index 1a14f67f..7e37a544 100644 --- a/crates/shirabe/src/config.rs +++ b/crates/shirabe/src/config.rs @@ -11,7 +11,7 @@ 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_match2, + 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, }; @@ -481,10 +481,9 @@ impl Config { .unwrap_or("") .to_string(); if is_composer - && preg_match2( + && preg_match( php_regex!(r"{^https?://(?:[a-z0-9-.]+\.)?packagist.org(/|$)}"), &repo_url, - 0, ) .is_some() { @@ -648,10 +647,9 @@ impl Config { // numbers with kb/mb/gb support, without env var support "cache-files-maxsize" => { let raw = self.config.get(key).map(php_to_string).unwrap_or_default(); - let Some(matches) = preg_match2( + let Some(matches) = preg_match( php_regex!(r"/^\s*([0-9.]+)\s*(?:([kmg])(?:i?b)?)?\s*$/i"), &raw, - 0, ) else { return Err(RuntimeException::new(format!( "Could not parse the value of '{}': {}", @@ -973,13 +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_match2( - php_regex!(r"{^(?:/|[a-z]:|[a-z0-9.]+://|\\\\\\\\)}i"), - path, - 0, - ) - .is_some() - { + if preg_match(php_regex!(r"{^(?:/|[a-z]:|[a-z0-9.]+://|\\\\\\\\)}i"), path).is_some() { return path.to_string(); } @@ -1021,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_match2(php_regex!(r"{^https?://}"), url, 0).is_none() { + if !filter_var_url(url) && preg_match(php_regex!(r"{^https?://}"), url).is_none() { return Ok(()); } |
