From e093b2be1c333e67c96aebb0a5291bea9ae3d6db Mon Sep 17 00:00:00 2001 From: nsfisis Date: Tue, 18 Aug 2026 01:57:02 +0900 Subject: 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) --- crates/shirabe/src/util/url.rs | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'crates/shirabe/src/util/url.rs') diff --git a/crates/shirabe/src/util/url.rs b/crates/shirabe/src/util/url.rs index 2754ef09..75841167 100644 --- a/crates/shirabe/src/util/url.rs +++ b/crates/shirabe/src/util/url.rs @@ -3,7 +3,7 @@ use crate::config::Config; use crate::util::GitHub; use shirabe_php_shim::{ - PhpMixed, in_array_strict, parse_url, php_regex, preg_match2, preg_replace, + PhpMixed, in_array_strict, parse_url, php_regex, preg_match, preg_replace, preg_replace_callback, }; @@ -16,12 +16,11 @@ impl Url { .unwrap_or_default(); if host == "api.github.com" || host == "github.com" || host == "www.github.com" { - if let Some(m) = preg_match2( + if let Some(m) = preg_match( php_regex!( r"{^https?://(?:www\.)?github\.com/([^/]+)/([^/]+)/(zip|tar)ball/(.+)$}i" ), &url, - 0, ) { url = format!( "https://api.github.com/repos/{}/{}/{}ball/{}", @@ -30,12 +29,11 @@ impl Url { m.get(3).unwrap_or_default(), r#ref ); - } else if let Some(m) = preg_match2( + } else if let Some(m) = preg_match( php_regex!( r"{^https?://(?:www\.)?github\.com/([^/]+)/([^/]+)/archive/.+\.(zip|tar)(?:\.gz)?$}i" ), &url, - 0, ) { url = format!( "https://api.github.com/repos/{}/{}/{}ball/{}", @@ -44,12 +42,11 @@ impl Url { m.get(3).unwrap_or_default(), r#ref ); - } else if let Some(m) = preg_match2( + } else if let Some(m) = preg_match( php_regex!( r"{^https?://api\.github\.com/repos/([^/]+)/([^/]+)/(zip|tar)ball(?:/.+)?$}i" ), &url, - 0, ) { url = format!( "https://api.github.com/repos/{}/{}/{}ball/{}", @@ -60,12 +57,11 @@ impl Url { ); } } else if host == "bitbucket.org" || host == "www.bitbucket.org" { - if let Some(m) = preg_match2( + if let Some(m) = preg_match( php_regex!( r"{^https?://(?:www\.)?bitbucket\.org/([^/]+)/([^/]+)/get/(.+)\.(zip|tar\.gz|tar\.bz2)$}i" ), &url, - 0, ) { url = format!( "https://bitbucket.org/{}/{}/get/{}.{}", @@ -76,12 +72,11 @@ impl Url { ); } } else if host == "gitlab.com" || host == "www.gitlab.com" { - if let Some(m) = preg_match2( + if let Some(m) = preg_match( php_regex!( r"{^https?://(?:www\.)?gitlab\.com/api/v[34]/projects/([^/]+)/repository/archive\.(zip|tar\.gz|tar\.bz2|tar)\?sha=.+$}i" ), &url, - 0, ) { url = format!( "https://gitlab.com/api/v4/projects/{}/repository/archive.{}?sha={}", @@ -173,13 +168,11 @@ impl Url { let user = m.name("user").unwrap_or_default().to_string(); let prefix = m.name("prefix").unwrap_or_default().to_string(); // if the username looks like a long (12char+) hex string, or a modern github token (e.g. ghp_xxx, github_pat_xxx) we obfuscate that - Ok( - if preg_match2(GitHub::GITHUB_TOKEN_REGEX, &user, 0).is_some() { - format!("{}***:***@", prefix) - } else { - format!("{}{}:***@", prefix, user) - }, - ) + Ok(if preg_match(GitHub::GITHUB_TOKEN_REGEX, &user).is_some() { + format!("{}***:***@", prefix) + } else { + format!("{}{}:***@", prefix, user) + }) }, &url, ) -- cgit v1.3.1-4-g156e