aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/util
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
commitfed0a6e7ac361af9b963c1f62411b1a85478230c (patch)
tree5cde64a24845c761890fbcbe05e0d702f1ec8df7 /crates/shirabe/src/util
parente093b2be1c333e67c96aebb0a5291bea9ae3d6db (diff)
downloadphp-shirabe-fed0a6e7ac361af9b963c1f62411b1a85478230c.tar.gz
php-shirabe-fed0a6e7ac361af9b963c1f62411b1a85478230c.tar.zst
php-shirabe-fed0a6e7ac361af9b963c1f62411b1a85478230c.zip
refactor(preg): add preg_is_match for existence-only call sites
The capture groups were discarded at 162 of the preg_match call sites, which only tested the Option. They now call preg_is_match, which lets the regex engine skip capture tracking. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/util')
-rw-r--r--crates/shirabe/src/util/auth_helper.rs4
-rw-r--r--crates/shirabe/src/util/composer_mirror.rs4
-rw-r--r--crates/shirabe/src/util/config_validator.rs13
-rw-r--r--crates/shirabe/src/util/filesystem.rs22
-rw-r--r--crates/shirabe/src/util/git.rs32
-rw-r--r--crates/shirabe/src/util/github.rs6
-rw-r--r--crates/shirabe/src/util/http/curl_downloader.rs7
-rw-r--r--crates/shirabe/src/util/http/response.rs4
-rw-r--r--crates/shirabe/src/util/http_downloader.rs6
-rw-r--r--crates/shirabe/src/util/platform.rs4
-rw-r--r--crates/shirabe/src/util/process_executor.rs15
-rw-r--r--crates/shirabe/src/util/remote_filesystem.rs17
-rw-r--r--crates/shirabe/src/util/url.rs4
13 files changed, 62 insertions, 76 deletions
diff --git a/crates/shirabe/src/util/auth_helper.rs b/crates/shirabe/src/util/auth_helper.rs
index 3da49258..72f50aa3 100644
--- a/crates/shirabe/src/util/auth_helper.rs
+++ b/crates/shirabe/src/util/auth_helper.rs
@@ -11,7 +11,7 @@ use crate::util::GitLab;
use indexmap::IndexMap;
use shirabe_php_shim::{
PhpMixed, RuntimeException, base64_encode, explode, in_array_loose, in_array_strict, is_array,
- is_string, json_decode_assoc, parse_url, php_regex, preg_match, str_replace, strpos,
+ is_string, json_decode_assoc, parse_url, php_regex, preg_is_match, str_replace, strpos,
strtolower, substr, trim,
};
@@ -536,7 +536,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_match(php_regex!(r"{^https?://api\.github\.com/}"), url).is_some() {
+ if preg_is_match(php_regex!(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 0fb38716..910c3835 100644
--- a/crates/shirabe/src/util/composer_mirror.rs
+++ b/crates/shirabe/src/util/composer_mirror.rs
@@ -1,6 +1,6 @@
//! ref: composer/src/Composer/Util/ComposerMirror.php
-use shirabe_php_shim::{hash, php_regex, preg_match, preg_replace};
+use shirabe_php_shim::{hash, php_regex, preg_is_match, preg_match, preg_replace};
pub struct ComposerMirror;
@@ -14,7 +14,7 @@ impl ComposerMirror {
pretty_version: Option<&str>,
) -> String {
let reference = reference.map(|r| {
- if preg_match(php_regex!(r"{^([a-f0-9]*|%reference%)$}"), r).is_some() {
+ if preg_is_match(php_regex!(r"{^([a-f0-9]*|%reference%)$}"), r) {
r.to_string()
} else {
hash("md5", r)
diff --git a/crates/shirabe/src/util/config_validator.rs b/crates/shirabe/src/util/config_validator.rs
index e9282a9f..f8018fe5 100644
--- a/crates/shirabe/src/util/config_validator.rs
+++ b/crates/shirabe/src/util/config_validator.rs
@@ -10,7 +10,7 @@ use crate::package::loader::ValidatingArrayLoader;
use indexmap::IndexMap;
use serde::de::Error as _;
use shirabe_php_shim::Catch as _;
-use shirabe_php_shim::{PhpMixed, php_regex, preg_match, preg_replace};
+use shirabe_php_shim::{PhpMixed, php_regex, preg_is_match, preg_replace};
use shirabe_spdx_licenses::SpdxLicenses;
#[derive(Debug)]
@@ -117,16 +117,13 @@ impl ConfigValidator {
for license in &licenses {
let spdx_license = license_validator.get_license_by_identifier(license);
if spdx_license.is_some_and(|l| l.is_deprecated_license_id) {
- if preg_match(php_regex!(r"{^[AL]?GPL-[123](\.[01])?\+$}i"), license).is_some()
- {
+ if preg_is_match(php_regex!(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_match(php_regex!(r"{^[AL]?GPL-[123](\.[01])?$}i"), license)
- .is_some()
- {
+ } else if preg_is_match(php_regex!(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
@@ -147,7 +144,7 @@ impl ConfigValidator {
if let Some(PhpMixed::String(name)) = manifest.get("name")
&& !name.is_empty()
- && preg_match(php_regex!(r"{[A-Z]}"), name).is_some()
+ && preg_is_match(php_regex!(r"{[A-Z]}"), name)
{
let suggest_name = preg_replace(
php_regex!(r"{(?:([a-z])([A-Z])|([A-Z])([A-Z][a-z]))}"),
@@ -224,7 +221,7 @@ impl ConfigValidator {
packages.extend(require_dev);
for (package, version) in &packages {
if let PhpMixed::String(version_str) = version
- && preg_match(php_regex!(r"{#}"), version_str).is_some()
+ && preg_is_match(php_regex!(r"{#}"), version_str)
{
warnings.push(format!(
"The package \"{}\" is pointing to a commit-ref, this is bad practice and can cause unforeseen issues.",
diff --git a/crates/shirabe/src/util/filesystem.rs b/crates/shirabe/src/util/filesystem.rs
index ae19a998..41b81b7b 100644
--- a/crates/shirabe/src/util/filesystem.rs
+++ b/crates/shirabe/src/util/filesystem.rs
@@ -8,9 +8,9 @@ use shirabe_php_shim::{
chdir, clearstatcache, clearstatcache2, copy, dirname, explode, fclose, feof, file_exists,
file_get_contents, file_put_contents, fileatime, filemtime, filesize, fopen, fread,
function_exists, fwrite, implode, is_dir, is_file, is_link, is_readable, lstat, mkdir,
- php_regex, preg_match, preg_replace, preg_replace_callback, rename, rmdir, rtrim, str_repeat,
- str_replace, strlen, strpos, strtoupper, strtr, substr, substr_count, symlink, touch, unlink,
- usleep, var_export,
+ php_regex, preg_is_match, preg_match, preg_replace, preg_replace_callback, rename, rmdir,
+ rtrim, str_repeat, str_replace, strlen, strpos, strtoupper, strtr, substr, substr_count,
+ symlink, touch, unlink, usleep, var_export,
};
use shirabe_symfony_filesystem::exception::IOException;
use shirabe_symfony_finder::Finder;
@@ -246,7 +246,7 @@ impl Filesystem {
return Ok(Some(true));
}
- if preg_match(php_regex!("{^(?:[a-z]:)?[/\\\\]+$}i"), directory).is_some() {
+ if preg_is_match(php_regex!("{^(?:[a-z]:)?[/\\\\]+$}i"), directory) {
return Err(RuntimeException::new(format!("Aborting an attempted deletion of {}, this was probably not intended, if it is a real use case please report it.", directory))
.into());
}
@@ -578,7 +578,7 @@ impl Filesystem {
let mut common_path = to.clone();
while strpos(&format!("{}/", from), &format!("{}/", common_path)) != Some(0)
&& "/" != common_path
- && preg_match(php_regex!("{^[A-Z]:/?$}i"), &common_path).is_none()
+ && !preg_is_match(php_regex!("{^[A-Z]:/?$}i"), &common_path)
{
common_path = strtr(&dirname(&common_path), "\\", "/");
}
@@ -635,7 +635,7 @@ impl Filesystem {
let mut common_path = to.clone();
while strpos(&format!("{}/", from), &format!("{}/", common_path)) != Some(0)
&& "/" != common_path
- && preg_match(php_regex!("{^[A-Z]:/?$}i"), &common_path).is_none()
+ && !preg_is_match(php_regex!("{^[A-Z]:/?$}i"), &common_path)
&& "." != common_path
{
common_path = strtr(&dirname(&common_path), "\\", "/");
@@ -778,7 +778,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_match(php_regex!("{^[/\\\\]+$}"), &path).is_none() {
+ if !preg_is_match(php_regex!("{^[/\\\\]+$}"), &path) {
path = rtrim(&path, Some("/\\"));
}
@@ -790,20 +790,18 @@ impl Filesystem {
// on windows, \\foo indicates network paths so we exclude those from local paths, however it is unsafe
// on linux as file:////foo (which would be a network path \\foo on windows) will resolve to /foo which could be a local path
if Platform::is_windows() {
- return preg_match(
+ return preg_is_match(
php_regex!(
"{^(file://(?!//)|/(?!/)|/?[a-z]:[\\\\/]|\\.\\.[\\\\/]|[a-z0-9_.-]+[\\\\/])}i"
),
path,
- )
- .is_some();
+ );
}
- preg_match(
+ preg_is_match(
php_regex!("{^(file://|/|/?[a-z]:[\\\\/]|\\.\\.[\\\\/]|[a-z0-9_.-]+[\\\\/])}i"),
path,
)
- .is_some()
}
pub fn get_platform_path(path: &str) -> String {
diff --git a/crates/shirabe/src/util/git.rs b/crates/shirabe/src/util/git.rs
index 2426780f..78c1acb5 100644
--- a/crates/shirabe/src/util/git.rs
+++ b/crates/shirabe/src/util/git.rs
@@ -17,8 +17,8 @@ use indexmap::IndexMap;
use shirabe_php_shim::{
AnyThrowable, CmpOp, InvalidArgumentException, PHP_EOL, PhpMixed, PregMatches,
RuntimeException, array_map, clearstatcache, explode, implode, in_array_loose, in_array_strict,
- is_dir, php_regex, preg_match, preg_quote, preg_replace, rawurldecode, rawurlencode,
- str_replace_array, strlen, strpos, substr, trim, version_compare,
+ is_dir, php_regex, preg_is_match, preg_match, preg_quote, preg_replace, rawurldecode,
+ rawurlencode, str_replace_array, strlen, strpos, substr, trim, version_compare,
};
use std::sync::Mutex;
@@ -209,7 +209,7 @@ impl Git {
status
};
- if preg_match(php_regex!(r"{^ssh://[^@]+@[^:]+:[^0-9]+}"), url).is_some() {
+ if preg_is_match(php_regex!(r"{^ssh://[^@]+@[^:]+:[^0-9]+}"), url) {
return Err(InvalidArgumentException::new(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.",
url
@@ -310,21 +310,19 @@ impl Git {
.collect(),
_ => vec![],
};
- let bypass_ssh_for_github = preg_match(
+ let bypass_ssh_for_github = preg_is_match(
format!(
"{{^git@{}:(.+?)\\.git$}}i",
Self::get_github_domains_regex(&self.config.borrow())
),
url,
- )
- .is_some()
- && !in_array_strict(
- "ssh".to_string(),
- &protocols_list
- .iter()
- .map(|s| PhpMixed::String(s.clone()))
- .collect::<Vec<_>>(),
- );
+ ) && !in_array_strict(
+ "ssh".to_string(),
+ &protocols_list
+ .iter()
+ .map(|s| PhpMixed::String(s.clone()))
+ .collect::<Vec<_>>(),
+ );
let mut auth: Option<IndexMap<String, Option<String>>> = None;
let mut credentials: Vec<String> = vec![];
@@ -915,7 +913,7 @@ impl Git {
pretty_version: Option<&str>,
) -> anyhow::Result<bool> {
if self.check_ref_is_in_mirror(dir, r#ref)? {
- if preg_match(php_regex!(r"{^[a-f0-9]{40}$}"), r#ref).is_some()
+ if preg_is_match(php_regex!(r"{^[a-f0-9]{40}$}"), r#ref)
&& let Some(pretty_version) = pretty_version
{
let branch = preg_replace(
@@ -949,17 +947,15 @@ impl Git {
// this can occur if a git tag gets created *after* the reference is already put into the cache, as the ref check above will then not sync the new tags
// see https://github.com/composer/composer/discussions/11002
if branches.is_some()
- && preg_match(
+ && !preg_is_match(
format!(r"{{^[\s*]*v?{}$}}m", preg_quote(&branch, None)),
branches.as_deref().unwrap_or(""),
)
- .is_none()
&& tags.is_some()
- && preg_match(
+ && !preg_is_match(
format!(r"{{^[\s*]*{}$}}m", preg_quote(&branch, None)),
tags.as_deref().unwrap_or(""),
)
- .is_none()
{
self.sync_mirror(url, dir)?;
}
diff --git a/crates/shirabe/src/util/github.rs b/crates/shirabe/src/util/github.rs
index a50f928a..ccfedcf8 100644
--- a/crates/shirabe/src/util/github.rs
+++ b/crates/shirabe/src/util/github.rs
@@ -10,7 +10,7 @@ use crate::util::ProcessExecutor;
use indexmap::IndexMap;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
- PhpMixed, date_local, in_array_loose, php_regex, preg_match, stripos, strtolower,
+ PhpMixed, date_local, in_array_loose, php_regex, preg_is_match, preg_match, stripos, strtolower,
};
#[derive(Debug)]
@@ -336,7 +336,7 @@ impl GitHub {
pub fn is_rate_limited(&self, headers: &[String]) -> bool {
for header in headers {
- if preg_match(php_regex!(r"{^x-ratelimit-remaining: *0$}i"), header.trim()).is_some() {
+ if preg_is_match(php_regex!(r"{^x-ratelimit-remaining: *0$}i"), header.trim()) {
return true;
}
}
@@ -346,7 +346,7 @@ impl GitHub {
pub fn requires_sso(&self, headers: &[String]) -> bool {
for header in headers {
- if preg_match(php_regex!(r"{^x-github-sso: required}i"), header.trim()).is_some() {
+ if preg_is_match(php_regex!(r"{^x-github-sso: required}i"), header.trim()) {
return true;
}
}
diff --git a/crates/shirabe/src/util/http/curl_downloader.rs b/crates/shirabe/src/util/http/curl_downloader.rs
index 6754f784..b1e89a07 100644
--- a/crates/shirabe/src/util/http/curl_downloader.rs
+++ b/crates/shirabe/src/util/http/curl_downloader.rs
@@ -32,7 +32,7 @@ use crate::util::http::Response;
use crate::util::{AuthHelper, PromptAuthResult, StoreAuth};
use indexmap::IndexMap;
use shirabe_php_shim::{
- PhpMixed, in_array_loose, in_array_strict, parse_url, php_regex, preg_match, preg_quote,
+ PhpMixed, in_array_loose, in_array_strict, parse_url, php_regex, preg_is_match, preg_quote,
preg_replace, rename, strpos, substr, unlink_silent,
};
use std::sync::atomic::{AtomicBool, Ordering};
@@ -146,7 +146,7 @@ impl CurlDownloader {
// 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_match(php_regex!(r"{^http://(repo\.)?packagist\.org/p/}"), url).is_none()
+ if !preg_is_match(php_regex!(r"{^http://(repo\.)?packagist\.org/p/}"), url)
|| (strpos(url, "$").is_none() && strpos(url, "%24").is_none())
{
self.config.borrow_mut().prohibit_url_by_config(
@@ -746,14 +746,13 @@ impl CurlDownloader {
&& substr(url, -4, None) == ".zip"
&& (location_header.is_none()
|| substr(location_header.as_deref().unwrap_or(""), -4, None) != ".zip")
- && preg_match(
+ && preg_is_match(
php_regex!(r"{^text/html\b}i"),
&response
.inner
.get_header("content-type")
.unwrap_or_default(),
)
- .is_some()
{
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 6fe95200..4f824baa 100644
--- a/crates/shirabe/src/util/http/response.rs
+++ b/crates/shirabe/src/util/http/response.rs
@@ -1,7 +1,7 @@
//! ref: composer/src/Composer/Util/Http/Response.php
use crate::json::JsonFile;
-use shirabe_php_shim::{PhpMixed, php_regex, preg_match, preg_quote};
+use shirabe_php_shim::{PhpMixed, php_regex, preg_is_match, preg_match, preg_quote};
#[derive(Debug)]
pub struct Response {
@@ -28,7 +28,7 @@ impl Response {
pub fn get_status_message(&self) -> Option<String> {
let mut value = None;
for header in &self.headers {
- if preg_match(php_regex!(r"{^HTTP/\S+ \d+}i"), header).is_some() {
+ if preg_is_match(php_regex!(r"{^HTTP/\S+ \d+}i"), 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());
diff --git a/crates/shirabe/src/util/http_downloader.rs b/crates/shirabe/src/util/http_downloader.rs
index f022ef4e..36ccb712 100644
--- a/crates/shirabe/src/util/http_downloader.rs
+++ b/crates/shirabe/src/util/http_downloader.rs
@@ -19,8 +19,8 @@ use indexmap::IndexMap;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
InvalidArgumentException, LogicException, PhpMixed, array_replace_recursive, extension_loaded,
- file_get_contents, function_exists, implode, is_numeric, php_regex, preg_match, preg_replace,
- rawurldecode, stream_context_create, stripos, strpos, substr, ucfirst,
+ file_get_contents, function_exists, implode, is_numeric, php_regex, preg_is_match, preg_match,
+ preg_replace, rawurldecode, stream_context_create, stripos, strpos, substr, ucfirst,
};
use shirabe_semver::constraint::SimpleConstraint;
@@ -485,7 +485,7 @@ impl HttpDownloader {
return false;
}
- if preg_match(php_regex!(r"{^https?://}i"), url).is_none() {
+ if !preg_is_match(php_regex!(r"{^https?://}i"), url) {
return false;
}
diff --git a/crates/shirabe/src/util/platform.rs b/crates/shirabe/src/util/platform.rs
index 3daf17c6..ccee2953 100644
--- a/crates/shirabe/src/util/platform.rs
+++ b/crates/shirabe/src/util/platform.rs
@@ -6,7 +6,7 @@ use shirabe_php_shim::{
PHP_ENV, PHP_SERVER, PhpMixed, PhpResource, PregMatches, RuntimeException, defined,
file_exists, file_get_contents, fstat, function_exists, getcwd, getenv, ini_get, is_readable,
mb_strlen, php_os_family, php_regex, posix_geteuid, posix_getpwuid, posix_getuid, posix_isatty,
- preg_match, preg_replace_callback, putenv, putenv_clear, realpath, stream_isatty, stripos,
+ preg_is_match, preg_replace_callback, putenv, putenv_clear, realpath, stream_isatty, stripos,
strlen, strtoupper, substr, usleep,
};
use std::sync::Mutex;
@@ -83,7 +83,7 @@ impl Platform {
/// Parses tildes and environment variables in paths.
pub fn expand_path(path: &str) -> String {
- if preg_match(php_regex!(r"#^~[\\/]#"), path).is_some() {
+ if preg_is_match(php_regex!(r"#^~[\\/]#"), path) {
return format!(
"{}{}",
Self::get_user_directory().unwrap(),
diff --git a/crates/shirabe/src/util/process_executor.rs b/crates/shirabe/src/util/process_executor.rs
index 64082064..6d609421 100644
--- a/crates/shirabe/src/util/process_executor.rs
+++ b/crates/shirabe/src/util/process_executor.rs
@@ -11,8 +11,9 @@ use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
LogicException, PHP_EOL, PhpMixed, PregMatches, RuntimeException, array_intersect, array_map,
escapeshellarg, explode, implode, in_array_strict, is_array, is_dir, is_numeric, is_string,
- php_regex, preg_match, preg_replace, preg_replace_callback, preg_replace2, preg_split, rtrim,
- str_replace, strcspn, strlen, strpbrk, strtolower, strtr_array, substr_replace, trim,
+ php_regex, preg_is_match, preg_match, preg_replace, preg_replace_callback, preg_replace2,
+ preg_split, rtrim, str_replace, strcspn, strlen, strpbrk, strtolower, strtr_array,
+ substr_replace, trim,
};
use shirabe_symfony_process::ExecutableFinder;
use shirabe_symfony_process::Process;
@@ -832,15 +833,13 @@ impl ProcessExecutor {
php_regex!(r"{://(?P<user>[^:/\s]+):(?P<password>[^@\s/]+)@}i"),
|m: &PregMatches| -> anyhow::Result<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
- if preg_match(
+ if preg_is_match(
GitHub::GITHUB_TOKEN_REGEX,
m.name("user").unwrap_or_default(),
- )
- .is_some()
- {
+ ) {
return Ok("://***:***@".to_string());
}
- if preg_match(r"{^[a-f0-9]{12,}$}", m.name("user").unwrap_or_default()).is_some() {
+ if preg_is_match(r"{^[a-f0-9]{12,}$}", m.name("user").unwrap_or_default()) {
return Ok("://***:***@".to_string());
}
@@ -903,7 +902,7 @@ impl ProcessExecutor {
-1,
Some(&mut dquotes),
);
- let meta = dquotes > 0 || preg_match(php_regex!(r"/%[^%]+%|![^!]+!/"), &argument).is_some();
+ let meta = dquotes > 0 || preg_is_match(php_regex!(r"/%[^%]+%|![^!]+!/"), &argument);
if !meta && !quote {
quote = strpbrk(&argument, "^&|<>()").is_some();
diff --git a/crates/shirabe/src/util/remote_filesystem.rs b/crates/shirabe/src/util/remote_filesystem.rs
index a7901567..b584d722 100644
--- a/crates/shirabe/src/util/remote_filesystem.rs
+++ b/crates/shirabe/src/util/remote_filesystem.rs
@@ -19,8 +19,8 @@ use shirabe_php_shim::{
STREAM_NOTIFY_PROGRESS, array_replace_recursive, base64_encode, explode, extension_loaded,
file_get_contents, file_get_contents5, file_put_contents, filter_var_boolean, gethostbyname,
http_clear_last_response_headers, http_get_last_response_headers, ini_get, json_decode_assoc,
- parse_url, php_regex, preg_match, preg_quote, preg_replace, strpos, strtolower, strtr, substr,
- trim, zlib_decode,
+ parse_url, php_regex, preg_is_match, preg_match, preg_quote, preg_replace, strpos, strtolower,
+ strtr, substr, trim, zlib_decode,
};
/// Result of `RemoteFilesystem::get` — string content, `true` (for copy), or `false`.
@@ -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_match(php_regex!("{^HTTP/\\S+ \\d+}i"), header).is_some() {
+ if preg_is_match(php_regex!("{^HTTP/\\S+ \\d+}i"), header) {
value = Some(header.clone());
}
}
@@ -285,12 +285,10 @@ impl RemoteFilesystem {
crate::io::DEBUG,
);
- if (preg_match(
+ if (!preg_is_match(
php_regex!("{^http://(repo\\.)?packagist\\.org/p/}"),
&file_url,
- )
- .is_none()
- || (strpos(&file_url, "$").is_none() && strpos(&file_url, "%24").is_none()))
+ ) || (strpos(&file_url, "$").is_none() && strpos(&file_url, "%24").is_none()))
&& !degraded_packagist
{
let _ = self.config.borrow_mut().prohibit_url_by_config(
@@ -474,11 +472,10 @@ impl RemoteFilesystem {
None,
) != ".zip")
&& content_type.is_some()
- && preg_match(
+ && preg_is_match(
php_regex!("{^text/html\\b}i"),
content_type.as_deref().unwrap_or(""),
- )
- .is_some();
+ );
if bitbucket_login_match {
result = None;
if retry_auth_failure {
diff --git a/crates/shirabe/src/util/url.rs b/crates/shirabe/src/util/url.rs
index 75841167..41556913 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_match, preg_replace,
+ PhpMixed, in_array_strict, parse_url, php_regex, preg_is_match, preg_match, preg_replace,
preg_replace_callback,
};
@@ -168,7 +168,7 @@ 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_match(GitHub::GITHUB_TOKEN_REGEX, &user).is_some() {
+ Ok(if preg_is_match(GitHub::GITHUB_TOKEN_REGEX, &user) {
format!("{}***:***@", prefix)
} else {
format!("{}{}:***@", prefix, user)