aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/util/url.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-14 11:24:36 +0900
committernsfisis <nsfisis@gmail.com>2026-06-14 11:28:19 +0900
commit716f44031a39c5e43fb441ecc470db76efc23dd4 (patch)
treee6f4a31e4bf55a0a8efb06d9dd4844c567e7390f /crates/shirabe/src/util/url.rs
parentef9118c788c1cbb22ca7721b6a9e40c2bf2fe243 (diff)
downloadphp-shirabe-716f44031a39c5e43fb441ecc470db76efc23dd4.tar.gz
php-shirabe-716f44031a39c5e43fb441ecc470db76efc23dd4.tar.zst
php-shirabe-716f44031a39c5e43fb441ecc470db76efc23dd4.zip
refactor(pcre): drop Result from Preg method return types
The Preg methods panic on PCRE failure (per the file header rationale), so their anyhow::Result wrappers never carried an Err. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/util/url.rs')
-rw-r--r--crates/shirabe/src/util/url.rs33
1 files changed, 10 insertions, 23 deletions
diff --git a/crates/shirabe/src/util/url.rs b/crates/shirabe/src/util/url.rs
index 8bcd73e..064c850 100644
--- a/crates/shirabe/src/util/url.rs
+++ b/crates/shirabe/src/util/url.rs
@@ -21,9 +21,7 @@ impl Url {
r"(?i)^https?://(?:www\.)?github\.com/([^/]+)/([^/]+)/(zip|tar)ball/(.+)$",
&url,
Some(&mut m),
- )
- .unwrap_or(false)
- {
+ ) {
url = format!(
"https://api.github.com/repos/{}/{}/{}ball/{}",
m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(),
@@ -35,9 +33,7 @@ impl Url {
r"(?i)^https?://(?:www\.)?github\.com/([^/]+)/([^/]+)/archive/.+\.(zip|tar)(?:\.gz)?$",
&url,
Some(&mut m),
- )
- .unwrap_or(false)
- {
+ ) {
url = format!(
"https://api.github.com/repos/{}/{}/{}ball/{}",
m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(),
@@ -49,9 +45,7 @@ impl Url {
r"(?i)^https?://api\.github\.com/repos/([^/]+)/([^/]+)/(zip|tar)ball(?:/.+)?$",
&url,
Some(&mut m),
- )
- .unwrap_or(false)
- {
+ ) {
url = format!(
"https://api.github.com/repos/{}/{}/{}ball/{}",
m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(),
@@ -66,9 +60,7 @@ impl Url {
r"(?i)^https?://(?:www\.)?bitbucket\.org/([^/]+)/([^/]+)/get/(.+)\.(zip|tar\.gz|tar\.bz2)$",
&url,
Some(&mut m),
- )
- .unwrap_or(false)
- {
+ ) {
url = format!(
"https://bitbucket.org/{}/{}/get/{}.{}",
m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(),
@@ -83,9 +75,7 @@ impl Url {
r"(?i)^https?://(?:www\.)?gitlab\.com/api/v[34]/projects/([^/]+)/repository/archive\.(zip|tar\.gz|tar\.bz2|tar)\?sha=.+$",
&url,
Some(&mut m),
- )
- .unwrap_or(false)
- {
+ ) {
url = format!(
"https://gitlab.com/api/v4/projects/{}/repository/archive.{}?sha={}",
m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(),
@@ -102,8 +92,7 @@ impl Url {
r"(?i)(/repos/[^/]+/[^/]+/(zip|tar)ball)(?:/.+)?$",
&format!("$1/{}", r#ref),
&url,
- )
- .unwrap_or(url);
+ );
} else if in_array(
PhpMixed::String(host.clone()),
&config.get("gitlab-domains"),
@@ -113,8 +102,7 @@ impl Url {
r"(?i)(/api/v[34]/projects/[^/]+/repository/archive\.(?:zip|tar\.gz|tar\.bz2|tar)\?sha=).+$",
&format!("${{1}}{}", r#ref),
&url,
- )
- .unwrap_or(url);
+ );
}
assert!(!url.is_empty());
@@ -176,7 +164,7 @@ impl Url {
pub fn sanitize(url: String) -> String {
// GitHub repository rename result in redirect locations containing the access_token as GET parameter
// e.g. https://api.github.com/repositories/9999999999?access_token=github_token
- let url = Preg::replace(r"([&?]access_token=)[^&]+", "$1***", &url).unwrap_or(url);
+ let url = Preg::replace(r"([&?]access_token=)[^&]+", "$1***", &url);
let url = Preg::replace_callback(
r"(?i)^(?P<prefix>[a-z0-9]+://)?(?P<user>[^:/\s@]+):(?P<password>[^@\s/]+)@",
@@ -190,15 +178,14 @@ impl Url {
.cloned()
.unwrap_or_default();
// 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
- if Preg::is_match(GitHub::GITHUB_TOKEN_REGEX, &user).unwrap_or(false) {
+ if Preg::is_match(GitHub::GITHUB_TOKEN_REGEX, &user) {
format!("{}***:***@", prefix)
} else {
format!("{}{}:***@", prefix, user)
}
},
&url,
- )
- .unwrap_or(url);
+ );
url
}