aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/util
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
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')
-rw-r--r--crates/shirabe/src/util/auth_helper.rs2
-rw-r--r--crates/shirabe/src/util/composer_mirror.rs12
-rw-r--r--crates/shirabe/src/util/config_validator.rs15
-rw-r--r--crates/shirabe/src/util/filesystem.rs24
-rw-r--r--crates/shirabe/src/util/forgejo_url.rs2
-rw-r--r--crates/shirabe/src/util/git.rs106
-rw-r--r--crates/shirabe/src/util/github.rs6
-rw-r--r--crates/shirabe/src/util/gitlab.rs3
-rw-r--r--crates/shirabe/src/util/hg.rs4
-rw-r--r--crates/shirabe/src/util/http/curl_downloader.rs8
-rw-r--r--crates/shirabe/src/util/http/response.rs4
-rw-r--r--crates/shirabe/src/util/http_downloader.rs12
-rw-r--r--crates/shirabe/src/util/no_proxy_pattern.rs2
-rw-r--r--crates/shirabe/src/util/perforce.rs3
-rw-r--r--crates/shirabe/src/util/platform.rs3
-rw-r--r--crates/shirabe/src/util/process_executor.rs33
-rw-r--r--crates/shirabe/src/util/remote_filesystem.rs41
-rw-r--r--crates/shirabe/src/util/svn.rs4
-rw-r--r--crates/shirabe/src/util/url.rs33
19 files changed, 122 insertions, 195 deletions
diff --git a/crates/shirabe/src/util/auth_helper.rs b/crates/shirabe/src/util/auth_helper.rs
index 8505081..d520270 100644
--- a/crates/shirabe/src/util/auth_helper.rs
+++ b/crates/shirabe/src/util/auth_helper.rs
@@ -529,7 +529,7 @@ impl AuthHelper {
}
} else if origin == "github.com" && password == "x-oauth-basic" {
// only add the access_token if it is actually a github API URL
- if Preg::is_match(r"{^https?://api\.github\.com/}", url)? {
+ if Preg::is_match(r"{^https?://api\.github\.com/}", url) {
headers.push(PhpMixed::String(format!(
"Authorization: token {}",
username,
diff --git a/crates/shirabe/src/util/composer_mirror.rs b/crates/shirabe/src/util/composer_mirror.rs
index 6f15a13..c0ff8d8 100644
--- a/crates/shirabe/src/util/composer_mirror.rs
+++ b/crates/shirabe/src/util/composer_mirror.rs
@@ -15,7 +15,7 @@ impl ComposerMirror {
pretty_version: Option<&str>,
) -> String {
let reference = reference.map(|r| {
- if Preg::is_match(r"^([a-f0-9]*|%reference%)$", r).unwrap_or(false) {
+ if Preg::is_match(r"^([a-f0-9]*|%reference%)$", r) {
r.to_string()
} else {
hash("md5", r)
@@ -59,9 +59,7 @@ impl ComposerMirror {
r"^(?:(?:https?|git)://github\.com/|git@github\.com:)([^/]+)/(.+?)(?:\.git)?$",
url,
Some(&mut gh_matches),
- )
- .unwrap_or(false)
- {
+ ) {
format!(
"gh-{}/{}",
gh_matches
@@ -77,9 +75,7 @@ impl ComposerMirror {
r"^https://bitbucket\.org/([^/]+)/(.+?)(?:\.git)?/?$",
url,
Some(&mut bb_matches),
- )
- .unwrap_or(false)
- {
+ ) {
format!(
"bb-{}/{}",
bb_matches
@@ -92,7 +88,7 @@ impl ComposerMirror {
.unwrap_or_default(),
)
} else {
- Preg::replace(r"[^a-z0-9_.-]", "-", url.trim_matches('/')).unwrap_or_default()
+ Preg::replace(r"[^a-z0-9_.-]", "-", url.trim_matches('/'))
};
["%package%", "%normalizedUrl%", "%type%"]
diff --git a/crates/shirabe/src/util/config_validator.rs b/crates/shirabe/src/util/config_validator.rs
index 5621841..90195e7 100644
--- a/crates/shirabe/src/util/config_validator.rs
+++ b/crates/shirabe/src/util/config_validator.rs
@@ -134,17 +134,13 @@ impl ConfigValidator {
_ => false,
};
if is_deprecated {
- if Preg::is_match(r"{^[AL]?GPL-[123](\.[01])?\+$}i", license)
- .unwrap_or(false)
- {
+ if Preg::is_match(r"{^[AL]?GPL-[123](\.[01])?\+$}i", license) {
warnings.push(format!(
"License \"{}\" is a deprecated SPDX license identifier, use \"{}-or-later\" instead",
license,
license.replace('+', "")
));
- } else if Preg::is_match(r"{^[AL]?GPL-[123](\.[01])?$}i", license)
- .unwrap_or(false)
- {
+ } else if Preg::is_match(r"{^[AL]?GPL-[123](\.[01])?$}i", license) {
warnings.push(format!(
"License \"{}\" is a deprecated SPDX license identifier, use \"{}-only\" or \"{}-or-later\" instead",
license, license, license
@@ -165,13 +161,12 @@ impl ConfigValidator {
}
if let Some(PhpMixed::String(name)) = manifest.get("name") {
- if !name.is_empty() && Preg::is_match(r"{[A-Z]}", name).unwrap_or(false) {
+ if !name.is_empty() && Preg::is_match(r"{[A-Z]}", name) {
let suggest_name = Preg::replace(
r"{(?:([a-z])([A-Z])|([A-Z])([A-Z][a-z]))}",
r"\1\3-\2\4",
name,
- )
- .unwrap_or_else(|_| name.clone());
+ );
let suggest_name = suggest_name.to_lowercase();
publish_errors.push(format!(
@@ -242,7 +237,7 @@ impl ConfigValidator {
packages.extend(require_dev);
for (package, version) in &packages {
if let PhpMixed::String(version_str) = version.as_ref() {
- if Preg::is_match(r"{#}", version_str).unwrap_or(false) {
+ if Preg::is_match(r"{#}", version_str) {
warnings.push(format!(
"The package \"{}\" is pointing to a commit-ref, this is bad practice and can cause unforeseen issues.",
package
diff --git a/crates/shirabe/src/util/filesystem.rs b/crates/shirabe/src/util/filesystem.rs
index 15f970d..cb0e4a5 100644
--- a/crates/shirabe/src/util/filesystem.rs
+++ b/crates/shirabe/src/util/filesystem.rs
@@ -193,7 +193,7 @@ impl Filesystem {
return Ok(Some(true));
}
- if Preg::is_match3("{^(?:[a-z]:)?[/\\\\]+$}i", directory, None).unwrap_or(false) {
+ if Preg::is_match3("{^(?:[a-z]:)?[/\\\\]+$}i", directory, None) {
return Err(RuntimeException {
message: format!("Aborting an attempted deletion of {}, this was probably not intended, if it is a real use case please report it.", directory),
code: 0,
@@ -541,7 +541,7 @@ impl Filesystem {
let mut common_path = to.clone();
while strpos(&format!("{}/", from), &format!("{}/", common_path)) != Some(0)
&& "/" != common_path
- && !Preg::is_match3("{^[A-Z]:/?$}i", &common_path, None).unwrap_or(false)
+ && !Preg::is_match3("{^[A-Z]:/?$}i", &common_path, None)
{
common_path = strtr(&dirname(&common_path), "\\", "/");
}
@@ -602,7 +602,7 @@ impl Filesystem {
let mut common_path = to.clone();
while strpos(&format!("{}/", from), &format!("{}/", common_path)) != Some(0)
&& "/" != common_path
- && !Preg::is_match3("{^[A-Z]:/?$}i", &common_path, None).unwrap_or(false)
+ && !Preg::is_match3("{^[A-Z]:/?$}i", &common_path, None)
&& "." != common_path
{
common_path = strtr(&dirname(&common_path), "\\", "/");
@@ -705,9 +705,7 @@ impl Filesystem {
"{^( [0-9a-z]{2,}+: (?: // (?: [a-z]: )? )? | [a-z]: )}ix",
&path,
Some(&mut prefix_match),
- )
- .unwrap_or(false)
- {
+ ) {
prefix = prefix_match
.get(&shirabe_external_packages::composer::pcre::CaptureKey::ByIndex(1))
.cloned()
@@ -746,8 +744,7 @@ impl Filesystem {
strtoupper(&s)
},
&prefix,
- )
- .unwrap_or_default();
+ );
format!("{}{}{}", prefix, absolute, implode("/", &parts))
}
@@ -757,7 +754,7 @@ impl Filesystem {
/// And other possible unforeseen disasters, see https://github.com/composer/composer/pull/9422
pub fn trim_trailing_slash(path: &str) -> String {
let mut path = path.to_string();
- if !Preg::is_match3("{^[/\\\\]+$}", &path, None).unwrap_or(false) {
+ if !Preg::is_match3("{^[/\\\\]+$}", &path, None) {
path = rtrim(&path, Some("/\\"));
}
@@ -773,8 +770,7 @@ impl Filesystem {
"{^(file://(?!//)|/(?!/)|/?[a-z]:[\\\\/]|\\.\\.[\\\\/]|[a-z0-9_.-]+[\\\\/])}i",
path,
None,
- )
- .unwrap_or(false);
+ );
}
Preg::is_match3(
@@ -782,17 +778,15 @@ impl Filesystem {
path,
None,
)
- .unwrap_or(false)
}
pub fn get_platform_path(path: &str) -> String {
let mut path = path.to_string();
if Platform::is_windows() {
- path = Preg::replace("{^(?:file:///([a-z]):?/)}i", "file://$1:/", &path)
- .unwrap_or_default();
+ path = Preg::replace("{^(?:file:///([a-z]):?/)}i", "file://$1:/", &path);
}
- Preg::replace("{^file://}i", "", &path).unwrap_or_default()
+ Preg::replace("{^file://}i", "", &path)
}
/// Cross-platform safe version of is_readable()
diff --git a/crates/shirabe/src/util/forgejo_url.rs b/crates/shirabe/src/util/forgejo_url.rs
index 90a1424..85f2238 100644
--- a/crates/shirabe/src/util/forgejo_url.rs
+++ b/crates/shirabe/src/util/forgejo_url.rs
@@ -42,7 +42,7 @@ impl ForgejoUrl {
shirabe_external_packages::composer::pcre::CaptureKey,
String,
> = indexmap::IndexMap::new();
- if !Preg::match3(Self::URL_REGEX, repo_url, Some(&mut matches)).unwrap_or(false) {
+ if !Preg::match3(Self::URL_REGEX, repo_url, Some(&mut matches)) {
return None;
}
use shirabe_external_packages::composer::pcre::CaptureKey;
diff --git a/crates/shirabe/src/util/git.rs b/crates/shirabe/src/util/git.rs
index 35f4940..5916f9b 100644
--- a/crates/shirabe/src/util/git.rs
+++ b/crates/shirabe/src/util/git.rs
@@ -118,7 +118,7 @@ impl Git {
map.insert("%url%".to_string(), url.to_string());
map.insert(
"%sanitizedUrl%".to_string(),
- Preg::replace(r"{://([^@]+?):(.+?)@}", "://", &url).unwrap_or_default(),
+ Preg::replace(r"{://([^@]+?):(.+?)@}", "://", &url),
);
array_map(
@@ -207,7 +207,7 @@ impl Git {
status
};
- if Preg::is_match(r"{^ssh://[^@]+@[^:]+:[^0-9]+}", url).unwrap_or(false) {
+ if Preg::is_match(r"{^ssh://[^@]+@[^:]+:[^0-9]+}", url) {
return Err(InvalidArgumentException {
message: format!(
"The source URL {} is invalid, ssh URLs should have a port number after \":\".\nUse ssh://git@example.com:22/path or just git@example.com:path if you do not want to provide a password or custom port.",
@@ -231,9 +231,7 @@ impl Git {
r"{^(?:composer|origin)\s+https?://(.+):(.+)@([^/]+)}im",
&output,
Some(&mut m),
- )
- .unwrap_or(false)
- {
+ ) {
let m3 = m.get(&CaptureKey::ByIndex(3)).cloned().unwrap_or_default();
if !self.io.has_authentication(&m3) {
self.io.borrow_mut().set_authentication(
@@ -258,9 +256,7 @@ impl Git {
),
url,
Some(&mut m),
- )
- .unwrap_or(false)
- {
+ ) {
let mut messages: Vec<String> = vec![];
let protocols_list: Vec<String> = match &protocols {
PhpMixed::List(l) => l
@@ -295,7 +291,6 @@ impl Git {
" ",
&self.process.borrow().get_error_output().to_string()
)
- .unwrap_or_default()
));
if initial_clone {
@@ -334,18 +329,16 @@ impl Git {
Self::get_github_domains_regex(&*self.config.borrow())
),
url,
- )
- .unwrap_or(false)
- && !in_array(
- PhpMixed::String("ssh".to_string()),
- &PhpMixed::List(
- protocols_list
- .iter()
- .map(|s| Box::new(PhpMixed::String(s.clone())))
- .collect(),
- ),
- true,
- );
+ ) && !in_array(
+ PhpMixed::String("ssh".to_string()),
+ &PhpMixed::List(
+ protocols_list
+ .iter()
+ .map(|s| Box::new(PhpMixed::String(s.clone())))
+ .collect(),
+ ),
+ true,
+ );
let mut auth: Option<IndexMap<String, Option<String>>> = None;
let mut credentials: Vec<String> = vec![];
@@ -368,17 +361,14 @@ impl Git {
),
url,
Some(&mut m),
- )
- .unwrap_or(false)
- || Preg::is_match3(
- &format!(
- "{{^https?://{}/(.*?)(?:\\.git)?$}}i",
- Self::get_github_domains_regex(&*self.config.borrow())
- ),
- url,
- Some(&mut m),
- )
- .unwrap_or(false);
+ ) || Preg::is_match3(
+ &format!(
+ "{{^https?://{}/(.*?)(?:\\.git)?$}}i",
+ Self::get_github_domains_regex(&*self.config.borrow())
+ ),
+ url,
+ Some(&mut m),
+ );
if github_matched {
let m1 = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
let m2 = m.get(&CaptureKey::ByIndex(2)).cloned().unwrap_or_default();
@@ -434,14 +424,11 @@ impl Git {
r"{^(https?)://(bitbucket\.org)/(.*?)(?:\.git)?$}i",
url,
Some(&mut m),
- )
- .unwrap_or(false)
- || Preg::is_match3(
- r"{^(git)@(bitbucket\.org):(.+?\.git)$}i",
- url,
- Some(&mut m),
- )
- .unwrap_or(false);
+ ) || Preg::is_match3(
+ r"{^(git)@(bitbucket\.org):(.+?\.git)$}i",
+ url,
+ Some(&mut m),
+ );
bb_matched
} {
// bitbucket either through oauth or app password, with fallback to ssh.
@@ -589,17 +576,14 @@ impl Git {
),
url,
Some(&mut m),
- )
- .unwrap_or(false)
- || Preg::is_match3(
- &format!(
- "{{^(https?)://{}/(.*)}}i",
- Self::get_gitlab_domains_regex(&*self.config.borrow())
- ),
- url,
- Some(&mut m),
- )
- .unwrap_or(false);
+ ) || Preg::is_match3(
+ &format!(
+ "{{^(https?)://{}/(.*)}}i",
+ Self::get_gitlab_domains_regex(&*self.config.borrow())
+ ),
+ url,
+ Some(&mut m),
+ );
gl_matched
} {
let mut m1 = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
@@ -947,11 +931,9 @@ impl Git {
pretty_version: Option<&str>,
) -> Result<bool> {
if self.check_ref_is_in_mirror(dir, r#ref)? {
- if Preg::is_match(r"{^[a-f0-9]{40}$}", r#ref).unwrap_or(false)
- && pretty_version.is_some()
- {
+ if Preg::is_match(r"{^[a-f0-9]{40}$}", r#ref) && pretty_version.is_some() {
let branch =
- Preg::replace(r"{(?:^dev-|(?:\.x)?-dev$)}i", "", &pretty_version.unwrap())?;
+ Preg::replace(r"{(?:^dev-|(?:\.x)?-dev$)}i", "", &pretty_version.unwrap());
let mut branches: Option<String> = None;
let mut tags: Option<String> = None;
let mut output = String::new();
@@ -982,13 +964,11 @@ impl Git {
&format!(r"{{^[\s*]*v?{}$}}m", preg_quote(&branch, None)),
branches.as_deref().unwrap_or(""),
)
- .unwrap_or(false)
&& tags.is_some()
&& !Preg::is_match(
&format!(r"{{^[\s*]*{}$}}m", preg_quote(&branch, None)),
tags.as_deref().unwrap_or(""),
)
- .unwrap_or(false)
{
self.sync_mirror(url, dir)?;
}
@@ -1076,7 +1056,7 @@ impl Git {
}
// Filter out "commit <hash>" lines for older git versions
- Preg::replace(r"{^commit [a-f0-9]{40}\n?}m", "", output).unwrap_or_default()
+ Preg::replace(r"{^commit [a-f0-9]{40}\n?}m", "", output)
}
fn check_ref_is_in_mirror(&mut self, dir: &str, r#ref: &str) -> Result<bool> {
@@ -1117,7 +1097,7 @@ impl Git {
/// @return array<int, string>|null
fn get_authentication_failure(&self, url: &str) -> Option<IndexMap<CaptureKey, String>> {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if !Preg::is_match3(r"{^(https?://)([^/]+)(.*)$}i", url, Some(&mut m)).unwrap_or(false) {
+ if !Preg::is_match3(r"{^(https?://)([^/]+)(.*)$}i", url, Some(&mut m)) {
return None;
}
@@ -1202,9 +1182,7 @@ impl Git {
.split_lines(output_mixed.as_string().unwrap_or(""));
for line in lines {
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(r"{^\s*HEAD branch:\s(.+)\s*$}m", &line, Some(&mut matches))
- .unwrap_or(false)
- {
+ if Preg::is_match3(r"{^\s*HEAD branch:\s(.+)\s*$}m", &line, Some(&mut matches)) {
return Ok(Some(
matches
.get(&CaptureKey::ByIndex(1))
@@ -1345,9 +1323,7 @@ impl Git {
r"/^git version (\d+(?:\.\d+)+)/m",
&output,
Some(&mut matches),
- )
- .unwrap_or(false)
- {
+ ) {
*version = Some(matches.get(&CaptureKey::ByIndex(1)).cloned());
}
}
diff --git a/crates/shirabe/src/util/github.rs b/crates/shirabe/src/util/github.rs
index 1cd78c1..766d75b 100644
--- a/crates/shirabe/src/util/github.rs
+++ b/crates/shirabe/src/util/github.rs
@@ -333,7 +333,7 @@ impl GitHub {
continue;
}
let mut caps: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::match3(r"{\burl=(?P<url>[^\s;]+)}", header, Some(&mut caps)).unwrap_or(false) {
+ if Preg::match3(r"{\burl=(?P<url>[^\s;]+)}", header, Some(&mut caps)) {
return caps.get(&CaptureKey::ByName("url".to_string())).cloned();
}
}
@@ -343,7 +343,7 @@ impl GitHub {
pub fn is_rate_limited(&self, headers: &[String]) -> bool {
for header in headers {
- if Preg::is_match(r"{^x-ratelimit-remaining: *0$}i", header.trim()).unwrap_or(false) {
+ if Preg::is_match(r"{^x-ratelimit-remaining: *0$}i", header.trim()) {
return true;
}
}
@@ -353,7 +353,7 @@ impl GitHub {
pub fn requires_sso(&self, headers: &[String]) -> bool {
for header in headers {
- if Preg::is_match(r"{^x-github-sso: required}i", header.trim()).unwrap_or(false) {
+ if Preg::is_match(r"{^x-github-sso: required}i", header.trim()) {
return true;
}
}
diff --git a/crates/shirabe/src/util/gitlab.rs b/crates/shirabe/src/util/gitlab.rs
index d42f1cf..3938a07 100644
--- a/crates/shirabe/src/util/gitlab.rs
+++ b/crates/shirabe/src/util/gitlab.rs
@@ -51,8 +51,7 @@ impl GitLab {
pub fn authorize_oauth(&mut self, origin_url: &str) -> bool {
// before composer 1.9, origin URLs had no port number in them
- let bc_origin_url =
- Preg::replace("{:\\d+}", "", origin_url).unwrap_or_else(|_| origin_url.to_string());
+ let bc_origin_url = Preg::replace("{:\\d+}", "", origin_url);
let gitlab_domains = self.config.borrow_mut().get("gitlab-domains");
let domains = match gitlab_domains.as_array() {
diff --git a/crates/shirabe/src/util/hg.rs b/crates/shirabe/src/util/hg.rs
index f5ee256..c8f5489 100644
--- a/crates/shirabe/src/util/hg.rs
+++ b/crates/shirabe/src/util/hg.rs
@@ -58,7 +58,7 @@ impl Hg {
r"(?i)^(?P<proto>ssh|https?)://(?:(?P<user>[^:@]+)(?::(?P<pass>[^:@]+))?@)?(?P<host>[^/]+)(?P<path>/.*)?",
&url,
&mut matches,
- )?;
+ );
if matched {
if self
@@ -151,7 +151,7 @@ impl Hg {
(),
) == 0
{
- if let Ok(Some(matches)) = Preg::is_match_with_indexed_captures(
+ if let Some(matches) = Preg::is_match_with_indexed_captures(
r"/^.+? (\d+(?:\.\d+)+)(?:\+.*?)?\)?\r?\n/",
&output,
) {
diff --git a/crates/shirabe/src/util/http/curl_downloader.rs b/crates/shirabe/src/util/http/curl_downloader.rs
index 37993f9..98f874a 100644
--- a/crates/shirabe/src/util/http/curl_downloader.rs
+++ b/crates/shirabe/src/util/http/curl_downloader.rs
@@ -333,7 +333,7 @@ impl CurlDownloader {
let original_options = options.clone();
// check URL can be accessed (i.e. is not insecure), but allow insecure Packagist calls to $hashed providers as file integrity is verified with sha256
- if !Preg::is_match(r"{^http://(repo\.)?packagist\.org/p/}", url).unwrap_or(false)
+ if !Preg::is_match(r"{^http://(repo\.)?packagist\.org/p/}", url)
|| (strpos(url, "$").is_none() && strpos(url, "%24").is_none())
{
self.config.borrow_mut().prohibit_url_by_config(
@@ -1582,7 +1582,7 @@ impl CurlDownloader {
),
&format!("\\1{}", location_header),
job_url,
- )?;
+ );
} else {
// Relative path; e.g. foo
// This actually differs from PHP which seems to add duplicate slashes.
@@ -1591,7 +1591,7 @@ impl CurlDownloader {
r"{^(.+/)[^/?]*(?:\?.*)?$}",
&format!("\\1{}", location_header),
job_url,
- )?;
+ );
}
}
}
@@ -1690,7 +1690,7 @@ impl CurlDownloader {
.inner
.get_header("content-type")
.unwrap_or_default(),
- )?
+ )
{
needs_auth_retry = Some("Bitbucket requires authentication and it was not provided");
}
diff --git a/crates/shirabe/src/util/http/response.rs b/crates/shirabe/src/util/http/response.rs
index 4810397..ad55fa2 100644
--- a/crates/shirabe/src/util/http/response.rs
+++ b/crates/shirabe/src/util/http/response.rs
@@ -29,7 +29,7 @@ impl Response {
pub fn get_status_message(&self) -> Option<String> {
let mut value = None;
for header in &self.headers {
- if Preg::is_match(r"(?i)^HTTP/\S+ \d+", header).unwrap_or(false) {
+ if Preg::is_match(r"(?i)^HTTP/\S+ \d+", header) {
// In case of redirects, headers contain the headers of all responses
// so we can not return directly and need to keep iterating
value = Some(header.clone());
@@ -69,7 +69,7 @@ impl Response {
shirabe_external_packages::composer::pcre::CaptureKey,
String,
> = indexmap::IndexMap::new();
- if Preg::match3(&pattern, header, Some(&mut matches)).unwrap_or(false) {
+ if Preg::match3(&pattern, header, Some(&mut matches)) {
if let Some(s) =
matches.get(&shirabe_external_packages::composer::pcre::CaptureKey::ByIndex(1))
{
diff --git a/crates/shirabe/src/util/http_downloader.rs b/crates/shirabe/src/util/http_downloader.rs
index b1da08f..9279518 100644
--- a/crates/shirabe/src/util/http_downloader.rs
+++ b/crates/shirabe/src/util/http_downloader.rs
@@ -314,9 +314,7 @@ impl HttpDownloader {
r"{^https?://([^:/]+):([^@/]+)@([^/]+)}i",
&request.url,
Some(&mut m),
- )
- .unwrap_or(false)
- {
+ ) {
self.io.borrow_mut().set_authentication(
origin.clone(),
rawurldecode(
@@ -664,7 +662,11 @@ impl HttpDownloader {
) -> Result<()> {
let clean_message = |msg: &str| -> anyhow::Result<String> {
if !io.is_decorated() {
- return Preg::replace(&format!("{{{}{}}}u", chr(27), "\\[[;\\d]*m"), "", msg);
+ return Ok(Preg::replace(
+ &format!("{{{}{}}}u", chr(27), "\\[[;\\d]*m"),
+ "",
+ msg,
+ ));
}
Ok(msg.to_string())
@@ -804,7 +806,7 @@ impl HttpDownloader {
return false;
}
- if !Preg::is_match(r"{^https?://}i", &job.request.url).unwrap_or(false) {
+ if !Preg::is_match(r"{^https?://}i", &job.request.url) {
return false;
}
diff --git a/crates/shirabe/src/util/no_proxy_pattern.rs b/crates/shirabe/src/util/no_proxy_pattern.rs
index dbca5d7..512b881 100644
--- a/crates/shirabe/src/util/no_proxy_pattern.rs
+++ b/crates/shirabe/src/util/no_proxy_pattern.rs
@@ -40,7 +40,7 @@ impl NoProxyPattern {
/// @param string $pattern NO_PROXY pattern
pub fn new(pattern: &str) -> Self {
// PHP: Preg::split('{[\s,]+}', $pattern, -1, PREG_SPLIT_NO_EMPTY)
- let host_names = Preg::split(r"{[\s,]+}", pattern).unwrap_or_default();
+ let host_names = Preg::split(r"{[\s,]+}", pattern);
let noproxy = host_names.is_empty() || host_names[0] == "*";
Self {
host_names,
diff --git a/crates/shirabe/src/util/perforce.rs b/crates/shirabe/src/util/perforce.rs
index 2a17fa9..1f64dcc 100644
--- a/crates/shirabe/src/util/perforce.rs
+++ b/crates/shirabe/src/util/perforce.rs
@@ -693,8 +693,7 @@ impl Perforce {
r"/[^A-Za-z0-9 ]/",
"",
&res_bits.get(4).cloned().unwrap_or_default(),
- )
- .unwrap_or_default();
+ );
possible_branches.insert(branch, res_bits.get(1).cloned().unwrap_or_default());
}
}
diff --git a/crates/shirabe/src/util/platform.rs b/crates/shirabe/src/util/platform.rs
index 5155e8f..797bac2 100644
--- a/crates/shirabe/src/util/platform.rs
+++ b/crates/shirabe/src/util/platform.rs
@@ -93,7 +93,7 @@ impl Platform {
/// Parses tildes and environment variables in paths.
pub fn expand_path(path: &str) -> String {
use shirabe_external_packages::composer::pcre::CaptureKey;
- if Preg::is_match(r"#^~[\\/]#", path).unwrap_or(false) {
+ if Preg::is_match(r"#^~[\\/]#", path) {
return format!(
"{}{}",
Self::get_user_directory().unwrap(),
@@ -137,7 +137,6 @@ impl Platform {
},
path,
)
- .unwrap_or_default()
}
/// @throws \RuntimeException If the user home could not reliably be determined
diff --git a/crates/shirabe/src/util/process_executor.rs b/crates/shirabe/src/util/process_executor.rs
index a681f2c..42bd0c8 100644
--- a/crates/shirabe/src/util/process_executor.rs
+++ b/crates/shirabe/src/util/process_executor.rs
@@ -206,8 +206,7 @@ impl ProcessExecutor {
let mut command_str = command.as_string().unwrap_or("").to_string();
if Platform::is_windows() {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(r"{^([^:/\\]++) }", &command_str, Some(&mut m)).unwrap_or(false)
- {
+ if Preg::is_match3(r"{^([^:/\\]++) }", &command_str, Some(&mut m)) {
let m1 = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
command_str = substr_replace(
&command_str,
@@ -647,7 +646,7 @@ impl ProcessExecutor {
if output.is_empty() {
vec![]
} else {
- Preg::split(r"{\r?\n}", &output).unwrap_or_default()
+ Preg::split(r"{\r?\n}", &output)
}
}
@@ -696,31 +695,25 @@ impl ProcessExecutor {
if Preg::is_match(
GitHub::GITHUB_TOKEN_REGEX,
m.get(&user_key).cloned().unwrap_or_default().as_str(),
- )
- .unwrap_or(false)
- {
+ ) {
return "://***:***@".to_string();
}
if Preg::is_match(
r"{^[a-f0-9]{12,}$}",
m.get(&user_key).cloned().unwrap_or_default().as_str(),
- )
- .unwrap_or(false)
- {
+ ) {
return "://***:***@".to_string();
}
format!("://{}:***@", m.get(&user_key).cloned().unwrap_or_default())
},
&command_string,
- )
- .unwrap_or_default();
+ );
let safe_command = Preg::replace(
r"{--password (.*[^\\]') }",
"--password '***' ",
&safe_command,
- )
- .unwrap_or_default();
+ );
self.io.as_ref().unwrap().write_error(&format!(
"Executing{} command ({}): {}",
if r#async { " async" } else { "" },
@@ -763,24 +756,20 @@ impl ProcessExecutor {
let mut quote = strpbrk(&argument, " \t,").is_some();
let mut dquotes: usize = 0;
// PHP: Preg::replace('/(\\\\*)"/', '$1$1\\"', $argument, -1, $dquotes)
- argument = Preg::replace5(r#"/(\\*)"/"#, r#"$1$1\""#, &argument, -1, &mut dquotes)
- .unwrap_or_default();
- let meta = dquotes > 0 || Preg::is_match(r"/%[^%]+%|![^!]+!/", &argument).unwrap_or(false);
+ argument = Preg::replace5(r#"/(\\*)"/"#, r#"$1$1\""#, &argument, -1, &mut dquotes);
+ let meta = dquotes > 0 || Preg::is_match(r"/%[^%]+%|![^!]+!/", &argument);
if !meta && !quote {
quote = strpbrk(&argument, "^&|<>()").is_some();
}
if quote {
- argument = format!(
- "\"{}\"",
- Preg::replace(r"/(\\*)$/", "$1$1", &argument).unwrap_or_default()
- );
+ argument = format!("\"{}\"", Preg::replace(r"/(\\*)$/", "$1$1", &argument));
}
if meta {
- argument = Preg::replace(r#"/(["^&|<>()%])/"#, "^$1", &argument).unwrap_or_default();
- argument = Preg::replace(r"/(!)/", "^^$1", &argument).unwrap_or_default();
+ argument = Preg::replace(r#"/(["^&|<>()%])/"#, "^$1", &argument);
+ argument = Preg::replace(r"/(!)/", "^^$1", &argument);
}
argument
diff --git a/crates/shirabe/src/util/remote_filesystem.rs b/crates/shirabe/src/util/remote_filesystem.rs
index a75f947..80b2617 100644
--- a/crates/shirabe/src/util/remote_filesystem.rs
+++ b/crates/shirabe/src/util/remote_filesystem.rs
@@ -145,7 +145,7 @@ impl RemoteFilesystem {
let mut value: Option<i64> = None;
for header in headers {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3("{^HTTP/\\S+ (\\d+)}i", header, Some(&mut m)).unwrap_or(false) {
+ if Preg::is_match3("{^HTTP/\\S+ (\\d+)}i", header, Some(&mut m)) {
value = m
.get(&CaptureKey::ByIndex(1))
.and_then(|s| s.parse().ok())
@@ -159,7 +159,7 @@ impl RemoteFilesystem {
pub fn find_status_message(&self, headers: &[String]) -> Option<String> {
let mut value: Option<String> = None;
for header in headers {
- if Preg::is_match("{^HTTP/\\S+ \\d+}i", header).unwrap_or(false) {
+ if Preg::is_match("{^HTTP/\\S+ \\d+}i", header) {
value = Some(header.clone());
}
}
@@ -283,7 +283,7 @@ impl RemoteFilesystem {
crate::io::DEBUG,
);
- if (!Preg::is_match("{^http://(repo\\.)?packagist\\.org/p/}", &file_url).unwrap_or(false)
+ if (!Preg::is_match("{^http://(repo\\.)?packagist\\.org/p/}", &file_url)
|| (strpos(&file_url, "$").is_none() && strpos(&file_url, "%24").is_none()))
&& !degraded_packagist
{
@@ -473,8 +473,7 @@ impl RemoteFilesystem {
None,
) != ".zip")
&& content_type.is_some()
- && Preg::is_match("{^text/html\\b}i", content_type.as_deref().unwrap_or(""))
- .unwrap_or(false);
+ && Preg::is_match("{^text/html\\b}i", content_type.as_deref().unwrap_or(""));
if bitbucket_login_match {
result = None;
if retry_auth_failure {
@@ -941,26 +940,20 @@ impl RemoteFilesystem {
.unwrap_or("")
.to_string();
- target_url = Some(
- Preg::replace(
- &format!(
- "{{^(.+(?://|@){}(?::\\d+)?)(?:[/\\?].*)?$}}",
- preg_quote(&url_host, None)
- ),
- &format!("\\1{}", location_header),
- &self.file_url,
- )
- .unwrap_or_else(|_| self.file_url.clone()),
- );
+ target_url = Some(Preg::replace(
+ &format!(
+ "{{^(.+(?://|@){}(?::\\d+)?)(?:[/\\?].*)?$}}",
+ preg_quote(&url_host, None)
+ ),
+ &format!("\\1{}", location_header),
+ &self.file_url,
+ ));
} else {
- target_url = Some(
- Preg::replace(
- "{^(.+/)[^/?]*(?:\\?.*)?$}",
- &format!("\\1{}", location_header),
- &self.file_url,
- )
- .unwrap_or_else(|_| self.file_url.clone()),
- );
+ target_url = Some(Preg::replace(
+ "{^(.+/)[^/?]*(?:\\?.*)?$}",
+ &format!("\\1{}", location_header),
+ &self.file_url,
+ ));
}
}
diff --git a/crates/shirabe/src/util/svn.rs b/crates/shirabe/src/util/svn.rs
index 8453a43..181fccf 100644
--- a/crates/shirabe/src/util/svn.rs
+++ b/crates/shirabe/src/util/svn.rs
@@ -443,9 +443,7 @@ impl Svn {
(),
) {
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(r"{(\d+(?:\.\d+)+)}", &output, Some(&mut matches))
- .unwrap_or(false)
- {
+ if Preg::is_match3(r"{(\d+(?:\.\d+)+)}", &output, Some(&mut matches)) {
*cached = Some(
matches
.get(&CaptureKey::ByIndex(1))
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
}