aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/util/url.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-18 01:57:02 +0900
committernsfisis <nsfisis@gmail.com>2026-08-18 01:57:02 +0900
commite093b2be1c333e67c96aebb0a5291bea9ae3d6db (patch)
tree0743fad689f419959c3a898605e21485087884fa /crates/shirabe/src/util/url.rs
parent050c56ef263d90d862ef565bc1762909110e02eb (diff)
downloadphp-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/util/url.rs')
-rw-r--r--crates/shirabe/src/util/url.rs29
1 files changed, 11 insertions, 18 deletions
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,
)