aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe/src/util')
-rw-r--r--crates/shirabe/src/util/auth_helper.rs6
-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.rs32
-rw-r--r--crates/shirabe/src/util/git.rs54
-rw-r--r--crates/shirabe/src/util/github.rs12
-rw-r--r--crates/shirabe/src/util/gitlab.rs6
-rw-r--r--crates/shirabe/src/util/hg.rs8
-rw-r--r--crates/shirabe/src/util/http/curl_downloader.rs10
-rw-r--r--crates/shirabe/src/util/http/response.rs4
-rw-r--r--crates/shirabe/src/util/http_downloader.rs14
-rw-r--r--crates/shirabe/src/util/no_proxy_pattern.rs6
-rw-r--r--crates/shirabe/src/util/perforce.rs6
-rw-r--r--crates/shirabe/src/util/platform.rs6
-rw-r--r--crates/shirabe/src/util/process_executor.rs24
-rw-r--r--crates/shirabe/src/util/remote_filesystem.rs21
-rw-r--r--crates/shirabe/src/util/svn.rs8
-rw-r--r--crates/shirabe/src/util/tls_helper.rs4
-rw-r--r--crates/shirabe/src/util/url.rs32
19 files changed, 171 insertions, 109 deletions
diff --git a/crates/shirabe/src/util/auth_helper.rs b/crates/shirabe/src/util/auth_helper.rs
index 1e997fd9..0a2dbf86 100644
--- a/crates/shirabe/src/util/auth_helper.rs
+++ b/crates/shirabe/src/util/auth_helper.rs
@@ -12,8 +12,8 @@ use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{
PHP_URL_HOST, PHP_URL_PATH, PHP_URL_SCHEME, PhpMixed, RuntimeException, base64_encode, explode,
- in_array, is_array, is_string, json_decode, parse_url, str_replace, strpos, strtolower, substr,
- trim,
+ in_array, is_array, is_string, json_decode, parse_url, php_regex, str_replace, strpos,
+ strtolower, substr, trim,
};
#[derive(Debug)]
@@ -516,7 +516,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(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 31f71279..a6f60621 100644
--- a/crates/shirabe/src/util/composer_mirror.rs
+++ b/crates/shirabe/src/util/composer_mirror.rs
@@ -1,7 +1,7 @@
//! ref: composer/src/Composer/Util/ComposerMirror.php
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
-use shirabe_php_shim::hash;
+use shirabe_php_shim::{hash, php_regex};
pub struct ComposerMirror;
@@ -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) {
+ if Preg::is_match(php_regex!(r"{^([a-f0-9]*|%reference%)$}"), r) {
r.to_string()
} else {
hash("md5", r)
@@ -56,7 +56,9 @@ impl ComposerMirror {
let mut gh_matches: indexmap::IndexMap<CaptureKey, String> = indexmap::IndexMap::new();
let mut bb_matches: indexmap::IndexMap<CaptureKey, String> = indexmap::IndexMap::new();
let normalized_url = if Preg::match3(
- r"#^(?:(?:https?|git)://github\.com/|git@github\.com:)([^/]+)/(.+?)(?:\.git)?$#",
+ php_regex!(
+ r"#^(?:(?:https?|git)://github\.com/|git@github\.com:)([^/]+)/(.+?)(?:\.git)?$#"
+ ),
url,
Some(&mut gh_matches),
) {
@@ -72,7 +74,7 @@ impl ComposerMirror {
.unwrap_or_default(),
)
} else if Preg::match3(
- r"#^https://bitbucket\.org/([^/]+)/(.+?)(?:\.git)?/?$#",
+ php_regex!(r"#^https://bitbucket\.org/([^/]+)/(.+?)(?:\.git)?/?$#"),
url,
Some(&mut bb_matches),
) {
@@ -88,7 +90,7 @@ impl ComposerMirror {
.unwrap_or_default(),
)
} else {
- Preg::replace(r"{[^a-z0-9_.-]}i", "-", url.trim_matches('/'))
+ Preg::replace(php_regex!(r"{[^a-z0-9_.-]}i"), "-", 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 4137a2d9..a9b89fd6 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_external_packages::composer::pcre::Preg;
-use shirabe_php_shim::PhpMixed;
+use shirabe_php_shim::{PhpMixed, php_regex};
use shirabe_spdx_licenses::SpdxLicenses;
#[derive(Debug)]
@@ -123,13 +123,16 @@ impl ConfigValidator {
_ => false,
};
if is_deprecated {
- if Preg::is_match(r"{^[AL]?GPL-[123](\.[01])?\+$}i", license) {
+ 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::is_match(r"{^[AL]?GPL-[123](\.[01])?$}i", license) {
+ } 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
@@ -151,10 +154,10 @@ impl ConfigValidator {
if let Some(PhpMixed::String(name)) = manifest.get("name")
&& !name.is_empty()
- && Preg::is_match(r"{[A-Z]}", name)
+ && Preg::is_match(php_regex!(r"{[A-Z]}"), name)
{
let suggest_name = Preg::replace(
- r"{(?:([a-z])([A-Z])|([A-Z])([A-Z][a-z]))}",
+ php_regex!(r"{(?:([a-z])([A-Z])|([A-Z])([A-Z][a-z]))}"),
r"\1\3-\2\4",
name,
);
@@ -228,7 +231,7 @@ impl ConfigValidator {
packages.extend(require_dev);
for (package, version) in &packages {
if let PhpMixed::String(version_str) = version
- && Preg::is_match(r"{#}", version_str)
+ && 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 d21a0e7d..b92bee94 100644
--- a/crates/shirabe/src/util/filesystem.rs
+++ b/crates/shirabe/src/util/filesystem.rs
@@ -11,9 +11,9 @@ use shirabe_php_shim::{
basename, chdir, clearstatcache, clearstatcache2, copy, dirname, error_get_last, 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, rename, rmdir, rtrim, str_contains, str_repeat, str_replace,
- str_starts_with, strlen, strpos, strtoupper, strtr, substr, substr_count, symlink, touch,
- unlink, usleep, var_export,
+ is_readable, lstat, mkdir, php_regex, rename, rmdir, rtrim, str_contains, str_repeat,
+ str_replace, str_starts_with, strlen, strpos, strtoupper, strtr, substr, substr_count, symlink,
+ touch, unlink, usleep, var_export,
};
use std::path::Path;
@@ -227,7 +227,7 @@ impl Filesystem {
return Ok(Some(true));
}
- if Preg::is_match3("{^(?:[a-z]:)?[/\\\\]+$}i", directory, None) {
+ if Preg::is_match3(php_regex!("{^(?:[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,
@@ -592,7 +592,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)
+ && !Preg::is_match3(php_regex!("{^[A-Z]:/?$}i"), &common_path, None)
{
common_path = strtr(&dirname(&common_path), "\\", "/");
}
@@ -649,7 +649,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)
+ && !Preg::is_match3(php_regex!("{^[A-Z]:/?$}i"), &common_path, None)
&& "." != common_path
{
common_path = strtr(&dirname(&common_path), "\\", "/");
@@ -756,7 +756,7 @@ impl Filesystem {
String,
> = indexmap::IndexMap::new();
if Preg::is_match3(
- "{^( [0-9a-z]{2,}+: (?: // (?: [a-z]: )? )? | [a-z]: )}ix",
+ php_regex!("{^( [0-9a-z]{2,}+: (?: // (?: [a-z]: )? )? | [a-z]: )}ix"),
&path,
Some(&mut prefix_match),
) {
@@ -785,7 +785,7 @@ impl Filesystem {
// ensure c: is normalized to C:
prefix = Preg::replace_callback(
- "{(^|://)[a-z]:$}i",
+ php_regex!("{(^|://)[a-z]:$}i"),
|m: &indexmap::IndexMap<
shirabe_external_packages::composer::pcre::CaptureKey,
String,
@@ -808,7 +808,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) {
+ if !Preg::is_match3(php_regex!("{^[/\\\\]+$}"), &path, None) {
path = rtrim(&path, Some("/\\"));
}
@@ -821,14 +821,16 @@ impl Filesystem {
// 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::is_match3(
- "{^(file://(?!//)|/(?!/)|/?[a-z]:[\\\\/]|\\.\\.[\\\\/]|[a-z0-9_.-]+[\\\\/])}i",
+ php_regex!(
+ "{^(file://(?!//)|/(?!/)|/?[a-z]:[\\\\/]|\\.\\.[\\\\/]|[a-z0-9_.-]+[\\\\/])}i"
+ ),
path,
None,
);
}
Preg::is_match3(
- "{^(file://|/|/?[a-z]:[\\\\/]|\\.\\.[\\\\/]|[a-z0-9_.-]+[\\\\/])}i",
+ php_regex!("{^(file://|/|/?[a-z]:[\\\\/]|\\.\\.[\\\\/]|[a-z0-9_.-]+[\\\\/])}i"),
path,
None,
)
@@ -837,10 +839,14 @@ impl Filesystem {
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);
+ path = Preg::replace(
+ php_regex!("{^(?:file:///([a-z]):?/)}i"),
+ "file://$1:/",
+ &path,
+ );
}
- Preg::replace("{^file://}i", "", &path)
+ Preg::replace(php_regex!("{^file://}i"), "", &path)
}
/// Cross-platform safe version of is_readable()
diff --git a/crates/shirabe/src/util/git.rs b/crates/shirabe/src/util/git.rs
index 4520759f..1e6768b1 100644
--- a/crates/shirabe/src/util/git.rs
+++ b/crates/shirabe/src/util/git.rs
@@ -17,8 +17,8 @@ use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
InvalidArgumentException, PHP_EOL, PhpMixed, RuntimeException, array_map, clearstatcache,
- explode, implode, in_array, is_dir, preg_quote, rawurldecode, rawurlencode, str_contains,
- str_ends_with, str_replace_array, strlen, strpos, substr, trim, version_compare,
+ explode, implode, in_array, is_dir, php_regex, preg_quote, rawurldecode, rawurlencode,
+ str_contains, str_ends_with, str_replace_array, strlen, strpos, substr, trim, version_compare,
};
use std::sync::Mutex;
@@ -114,7 +114,7 @@ impl Git {
map.insert("%url%".to_string(), url.to_string());
map.insert(
"%sanitizedUrl%".to_string(),
- Preg::replace(r"{://([^@]+?):(.+?)@}", "://", url),
+ Preg::replace(php_regex!(r"{://([^@]+?):(.+?)@}"), "://", url),
);
array_map(
@@ -215,7 +215,7 @@ impl Git {
status
};
- if Preg::is_match(r"{^ssh://[^@]+@[^:]+:[^0-9]+}", url) {
+ if Preg::is_match(php_regex!(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.",
@@ -236,7 +236,7 @@ impl Git {
);
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- r"{^(?:composer|origin)\s+https?://(.+):(.+)@([^/]+)}im",
+ php_regex!(r"{^(?:composer|origin)\s+https?://(.+):(.+)@([^/]+)}im"),
&output,
Some(&mut m),
) {
@@ -258,7 +258,7 @@ impl Git {
// @phpstan-ignore composerPcre.maybeUnsafeStrictGroups
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- &format!(
+ format!(
"{{^(?:https?|git)://{}/(.*)}}",
Self::get_github_domains_regex(&self.config.borrow())
),
@@ -326,7 +326,7 @@ impl Git {
_ => vec![],
};
let bypass_ssh_for_github = Preg::is_match(
- &format!(
+ format!(
"{{^git@{}:(.+?)\\.git$}}i",
Self::get_github_domains_regex(&self.config.borrow())
),
@@ -357,14 +357,14 @@ impl Git {
// @phpstan-ignore composerPcre.maybeUnsafeStrictGroups
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
let github_matched = Preg::is_match3(
- &format!(
+ format!(
"{{^git@{}:(.+?)\\.git$}}i",
Self::get_github_domains_regex(&self.config.borrow())
),
url,
Some(&mut m),
) || Preg::is_match3(
- &format!(
+ format!(
"{{^https?://{}/(.*?)(?:\\.git)?$}}i",
Self::get_github_domains_regex(&self.config.borrow())
),
@@ -422,11 +422,11 @@ impl Git {
error_msg = self.process.borrow().get_error_output().to_string();
}
} else if Preg::is_match3(
- r"{^(https?)://(bitbucket\.org)/(.*?)(?:\.git)?$}i",
+ php_regex!(r"{^(https?)://(bitbucket\.org)/(.*?)(?:\.git)?$}i"),
url,
Some(&mut m),
) || Preg::is_match3(
- r"{^(git)@(bitbucket\.org):(.+?\.git)$}i",
+ php_regex!(r"{^(git)@(bitbucket\.org):(.+?\.git)$}i"),
url,
Some(&mut m),
) {
@@ -568,14 +568,14 @@ impl Git {
error_msg = self.process.borrow().get_error_output().to_string();
} else if Preg::is_match3(
- &format!(
+ format!(
"{{^(git)@{}:(.+?\\.git)$}}i",
Self::get_gitlab_domains_regex(&self.config.borrow())
),
url,
Some(&mut m),
) || Preg::is_match3(
- &format!(
+ format!(
"{{^(https?)://{}/(.*)}}i",
Self::get_gitlab_domains_regex(&self.config.borrow())
),
@@ -924,10 +924,14 @@ impl Git {
pretty_version: Option<&str>,
) -> anyhow::Result<bool> {
if self.check_ref_is_in_mirror(dir, r#ref)? {
- if Preg::is_match(r"{^[a-f0-9]{40}$}", r#ref)
+ if Preg::is_match(php_regex!(r"{^[a-f0-9]{40}$}"), r#ref)
&& let Some(pretty_version) = pretty_version
{
- let branch = Preg::replace(r"{(?:^dev-|(?:\.x)?-dev$)}i", "", pretty_version);
+ let branch = Preg::replace(
+ php_regex!(r"{(?:^dev-|(?:\.x)?-dev$)}i"),
+ "",
+ pretty_version,
+ );
let mut branches: Option<String> = None;
let mut tags: Option<String> = None;
let mut output = String::new();
@@ -955,12 +959,12 @@ impl Git {
// see https://github.com/composer/composer/discussions/11002
if branches.is_some()
&& !Preg::is_match(
- &format!(r"{{^[\s*]*v?{}$}}m", preg_quote(&branch, None)),
+ format!(r"{{^[\s*]*v?{}$}}m", preg_quote(&branch, None)),
branches.as_deref().unwrap_or(""),
)
&& tags.is_some()
&& !Preg::is_match(
- &format!(r"{{^[\s*]*{}$}}m", preg_quote(&branch, None)),
+ format!(r"{{^[\s*]*{}$}}m", preg_quote(&branch, None)),
tags.as_deref().unwrap_or(""),
)
{
@@ -1050,7 +1054,7 @@ impl Git {
}
// Filter out "commit <hash>" lines for older git versions
- Preg::replace(r"{^commit [a-f0-9]{40}\n?}m", "", output)
+ Preg::replace(php_regex!(r"{^commit [a-f0-9]{40}\n?}m"), "", output)
}
fn check_ref_is_in_mirror(&mut self, dir: &str, r#ref: &str) -> anyhow::Result<bool> {
@@ -1091,7 +1095,11 @@ 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)) {
+ if !Preg::is_match3(
+ php_regex!(r"{^(https?://)([^/]+)(.*)$}i"),
+ url,
+ Some(&mut m),
+ ) {
return None;
}
@@ -1176,7 +1184,11 @@ 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)) {
+ if Preg::is_match3(
+ php_regex!(r"{^\s*HEAD branch:\s(.+)\s*$}m"),
+ &line,
+ Some(&mut matches),
+ ) {
return Ok(Some(
matches
.get(&CaptureKey::ByIndex(1))
@@ -1314,7 +1326,7 @@ impl Git {
if exit_code == 0 {
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- r"/^git version (\d+(?:\.\d+)+)/m",
+ php_regex!(r"/^git version (\d+(?:\.\d+)+)/m"),
&output,
Some(&mut matches),
) {
diff --git a/crates/shirabe/src/util/github.rs b/crates/shirabe/src/util/github.rs
index 905026a6..e8e83ddd 100644
--- a/crates/shirabe/src/util/github.rs
+++ b/crates/shirabe/src/util/github.rs
@@ -9,7 +9,7 @@ use crate::util::HttpDownloader;
use crate::util::ProcessExecutor;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
-use shirabe_php_shim::{PhpMixed, date, stripos, strtolower};
+use shirabe_php_shim::{PhpMixed, date, php_regex, stripos, strtolower};
#[derive(Debug)]
pub struct GitHub {
@@ -331,7 +331,11 @@ impl GitHub {
continue;
}
let mut caps: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::match3(r"{\burl=(?P<url>[^\s;]+)}", header, Some(&mut caps)) {
+ if Preg::match3(
+ php_regex!(r"{\burl=(?P<url>[^\s;]+)}"),
+ header,
+ Some(&mut caps),
+ ) {
return caps.get(&CaptureKey::ByName("url".to_string())).cloned();
}
}
@@ -341,7 +345,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()) {
+ if Preg::is_match(php_regex!(r"{^x-ratelimit-remaining: *0$}i"), header.trim()) {
return true;
}
}
@@ -351,7 +355,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()) {
+ if Preg::is_match(php_regex!(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 eae26f0e..4a636efa 100644
--- a/crates/shirabe/src/util/gitlab.rs
+++ b/crates/shirabe/src/util/gitlab.rs
@@ -10,7 +10,9 @@ use crate::util::HttpDownloader;
use crate::util::ProcessExecutor;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
-use shirabe_php_shim::{PhpMixed, RuntimeException, http_build_query, json_decode, time};
+use shirabe_php_shim::{
+ PhpMixed, RuntimeException, http_build_query, json_decode, php_regex, time,
+};
#[derive(Debug)]
pub struct GitLab {
@@ -50,7 +52,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);
+ let bc_origin_url = Preg::replace(php_regex!("{:\\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 56e5044f..9f5ea3b5 100644
--- a/crates/shirabe/src/util/hg.rs
+++ b/crates/shirabe/src/util/hg.rs
@@ -6,7 +6,7 @@ use crate::io::IOInterfaceImmutable;
use crate::util::ProcessExecutor;
use crate::util::Url;
use shirabe_external_packages::composer::pcre::Preg;
-use shirabe_php_shim::rawurlencode;
+use shirabe_php_shim::{php_regex, rawurlencode};
use std::sync::OnceLock;
static VERSION: OnceLock<Option<String>> = OnceLock::new();
@@ -58,7 +58,9 @@ impl Hg {
// Try with the authentication information available
let mut matches: indexmap::IndexMap<String, String> = indexmap::IndexMap::new();
let matched = Preg::is_match_named(
- r"{^(?P<proto>ssh|https?)://(?:(?P<user>[^:@]+)(?::(?P<pass>[^:@]+))?@)?(?P<host>[^/]+)(?P<path>/.*)?}mi",
+ php_regex!(
+ r"{^(?P<proto>ssh|https?)://(?:(?P<user>[^:@]+)(?::(?P<pass>[^:@]+))?@)?(?P<host>[^/]+)(?P<path>/.*)?}mi"
+ ),
&url,
&mut matches,
);
@@ -152,7 +154,7 @@ impl Hg {
None,
) == 0
&& let Some(matches) = Preg::is_match_with_indexed_captures(
- r"/^.+? (\d+(?:\.\d+)+)(?:\+.*?)?\)?\r?\n/",
+ php_regex!(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 47260a85..508aa56e 100644
--- a/crates/shirabe/src/util/http/curl_downloader.rs
+++ b/crates/shirabe/src/util/http/curl_downloader.rs
@@ -33,7 +33,7 @@ use crate::util::{AuthHelper, PromptAuthResult, StoreAuth};
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{
- PhpMixed, in_array, parse_url, preg_quote, rename, strpos, substr, unlink_silent,
+ PhpMixed, in_array, parse_url, php_regex, preg_quote, rename, strpos, substr, unlink_silent,
};
use std::sync::atomic::{AtomicBool, Ordering};
@@ -150,7 +150,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::is_match(r"{^http://(repo\.)?packagist\.org/p/}", url)
+ 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(
@@ -659,7 +659,7 @@ impl CurlDownloader {
let url_host = parse_url(url, shirabe_php_shim::PHP_URL_HOST);
let url_host_str = url_host.as_string().unwrap_or("");
target_url = Preg::replace(
- &format!(
+ format!(
r"{{^(.+(?://|@){}(?::\d+)?)(?:[/\?].*)?$}}",
preg_quote(url_host_str, None)
),
@@ -669,7 +669,7 @@ impl CurlDownloader {
} else {
// Relative path; e.g. foo
target_url = Preg::replace(
- r"{^(.+/)[^/?]*(?:\?.*)?$}",
+ php_regex!(r"{^(.+/)[^/?]*(?:\?.*)?$}"),
&format!("\\1{}", location_header),
url,
);
@@ -754,7 +754,7 @@ impl CurlDownloader {
&& (location_header.is_none()
|| substr(location_header.as_deref().unwrap_or(""), -4, None) != ".zip")
&& Preg::is_match(
- r"{^text/html\b}i",
+ php_regex!(r"{^text/html\b}i"),
&response
.inner
.get_header("content-type")
diff --git a/crates/shirabe/src/util/http/response.rs b/crates/shirabe/src/util/http/response.rs
index 5398fe25..3ee538d5 100644
--- a/crates/shirabe/src/util/http/response.rs
+++ b/crates/shirabe/src/util/http/response.rs
@@ -2,7 +2,7 @@
use crate::json::JsonFile;
use shirabe_external_packages::composer::pcre::Preg;
-use shirabe_php_shim::{PhpMixed, preg_quote};
+use shirabe_php_shim::{PhpMixed, php_regex, preg_quote};
#[derive(Debug)]
pub struct Response {
@@ -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"{^HTTP/\S+ \d+}i", header) {
+ 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 98678ad2..b055a515 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_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
InvalidArgumentException, LogicException, PhpMixed, array_replace_recursive, chr,
- extension_loaded, file_get_contents, function_exists, implode, is_numeric, rawurldecode,
- stream_context_create, stripos, strpos, substr, ucfirst,
+ extension_loaded, file_get_contents, function_exists, implode, is_numeric, php_regex,
+ rawurldecode, stream_context_create, stripos, strpos, substr, ucfirst,
};
use shirabe_semver::constraint::SimpleConstraint;
@@ -253,7 +253,11 @@ impl HttpDownloader {
// capture username/password from URL if there is one
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(r"{^https?://([^:/]+):([^@/]+)@([^/]+)}i", url, Some(&mut m)) {
+ if Preg::is_match3(
+ php_regex!(r"{^https?://([^:/]+):([^@/]+)@([^/]+)}i"),
+ url,
+ Some(&mut m),
+ ) {
self.io.borrow_mut().set_authentication(
origin.clone(),
rawurldecode(
@@ -378,7 +382,7 @@ impl HttpDownloader {
let clean_message = |msg: &str| -> anyhow::Result<String> {
if !io.is_decorated() {
return Ok(Preg::replace(
- &format!("{{{}{}}}u", chr(27), "\\[[;\\d]*m"),
+ format!("{{{}{}}}u", chr(27), "\\[[;\\d]*m"),
"",
msg,
));
@@ -515,7 +519,7 @@ impl HttpDownloader {
return false;
}
- if !Preg::is_match(r"{^https?://}i", url) {
+ if !Preg::is_match(php_regex!(r"{^https?://}i"), url) {
return false;
}
diff --git a/crates/shirabe/src/util/no_proxy_pattern.rs b/crates/shirabe/src/util/no_proxy_pattern.rs
index 0a3d5640..dc91a256 100644
--- a/crates/shirabe/src/util/no_proxy_pattern.rs
+++ b/crates/shirabe/src/util/no_proxy_pattern.rs
@@ -4,8 +4,8 @@ use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{
PHP_URL_HOST, PHP_URL_PORT, PHP_URL_SCHEME, PhpMixed, RuntimeException, array_key_exists, chr,
- empty, explode, filter_var_int_with_range, filter_var_ip, inet_pton, ltrim, parse_url, str_pad,
- str_repeat, stripos, strlen, strpbrk, strpos, substr, substr_count, unpack,
+ empty, explode, filter_var_int_with_range, filter_var_ip, inet_pton, ltrim, parse_url,
+ php_regex, str_pad, str_repeat, stripos, strlen, strpbrk, strpos, substr, substr_count, unpack,
};
/// Tests URLs against NO_PROXY patterns
@@ -38,7 +38,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);
+ let host_names = Preg::split(php_regex!(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 389618ed..e39ed3c2 100644
--- a/crates/shirabe/src/util/perforce.rs
+++ b/crates/shirabe/src/util/perforce.rs
@@ -11,8 +11,8 @@ use shirabe_external_packages::symfony::process::ExecutableFinder;
use shirabe_external_packages::symfony::process::Process;
use shirabe_php_shim::{
Exception, PHP_EOL, PhpMixed, PhpResource, chdir, date, explode, fclose, feof, fgets,
- file_get_contents, fopen, fwrite, gethostname, json_decode, str_replace_array, strcmp, strlen,
- strpos, strrpos, substr, time, trim,
+ file_get_contents, fopen, fwrite, gethostname, json_decode, php_regex, str_replace_array,
+ strcmp, strlen, strpos, strrpos, substr, time, trim,
};
/// @phpstan-type RepoConfig array{unique_perforce_client_name?: string, depot?: string, branch?: string, p4user?: string, p4password?: string}
@@ -690,7 +690,7 @@ impl Perforce {
let res_bits = explode(" ", line);
if res_bits.len() > 4 {
let branch = Preg::replace(
- r"/[^A-Za-z0-9 ]/",
+ php_regex!(r"/[^A-Za-z0-9 ]/"),
"",
&res_bits.get(4).cloned().unwrap_or_default(),
);
diff --git a/crates/shirabe/src/util/platform.rs b/crates/shirabe/src/util/platform.rs
index 45ddb306..81f2adbb 100644
--- a/crates/shirabe/src/util/platform.rs
+++ b/crates/shirabe/src/util/platform.rs
@@ -6,7 +6,7 @@ use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{
PHP_ENV, PHP_SERVER, PhpMixed, PhpResource, RuntimeException, defined, file_exists,
file_get_contents, fstat, function_exists, getcwd, getenv, in_array, ini_get, is_array,
- is_readable, mb_strlen, php_os_family, posix_geteuid, posix_getpwuid, posix_getuid,
+ is_readable, mb_strlen, php_os_family, php_regex, posix_geteuid, posix_getpwuid, posix_getuid,
posix_isatty, putenv, putenv_clear, realpath, stream_isatty, stripos, strlen, strtoupper,
substr, usleep,
};
@@ -90,7 +90,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) {
+ if Preg::is_match(php_regex!(r"#^~[\\/]#"), path) {
return format!(
"{}{}",
Self::get_user_directory().unwrap(),
@@ -103,7 +103,7 @@ impl Platform {
// only for the `%VAR%` form. The Rust regex crate does not support conditionals, so the
// two forms are written as an explicit alternation: `$VAR` or `%VAR%`.
Preg::replace_callback(
- r"#^(?:\$(?P<dvar>\w+)|%(?P<pvar>\w+)%)(?P<path>.*)#",
+ php_regex!(r"#^(?:\$(?P<dvar>\w+)|%(?P<pvar>\w+)%)(?P<path>.*)#"),
|matches: &indexmap::IndexMap<CaptureKey, String>| -> String {
let var = matches
.get(&CaptureKey::ByName("dvar".to_string()))
diff --git a/crates/shirabe/src/util/process_executor.rs b/crates/shirabe/src/util/process_executor.rs
index 463e5115..e2b1422d 100644
--- a/crates/shirabe/src/util/process_executor.rs
+++ b/crates/shirabe/src/util/process_executor.rs
@@ -14,7 +14,7 @@ use shirabe_external_packages::symfony::process::exception::ProcessSignaledExcep
use shirabe_external_packages::symfony::process::exception::RuntimeException as SymfonyProcessRuntimeException;
use shirabe_php_shim::{
LogicException, PHP_EOL, PhpMixed, array_intersect, array_map, call_user_func, escapeshellarg,
- explode, implode, in_array, is_array, is_dir, is_numeric, is_string, rtrim, sprintf,
+ explode, implode, in_array, is_array, is_dir, is_numeric, is_string, php_regex, rtrim, sprintf,
str_replace, strcspn, strlen, strpbrk, strtolower, strtr_array, substr_replace, trim, usleep,
};
use std::sync::{LazyLock, Mutex};
@@ -236,7 +236,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)) {
+ if Preg::is_match3(php_regex!(r"{^([^:/\\]++) }"), &command_str, Some(&mut m)) {
let m1 = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
command_str = substr_replace(
&command_str,
@@ -870,7 +870,7 @@ impl ProcessExecutor {
if output.is_empty() {
vec![]
} else {
- Preg::split(r"{\r?\n}", &output)
+ Preg::split(php_regex!(r"{\r?\n}"), &output)
}
}
@@ -912,7 +912,7 @@ impl ProcessExecutor {
String::new()
};
let safe_command = Preg::replace_callback(
- r"{://(?P<user>[^:/\s]+):(?P<password>[^@\s/]+)@}i",
+ php_regex!(r"{://(?P<user>[^:/\s]+):(?P<password>[^@\s/]+)@}i"),
|m: &IndexMap<CaptureKey, String>| -> String {
let user_key = CaptureKey::ByName("user".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
@@ -934,7 +934,7 @@ impl ProcessExecutor {
&command_string,
);
let safe_command = Preg::replace(
- r"{--password (.*[^\\]') }",
+ php_regex!(r"{--password (.*[^\\]') }"),
"--password '***' ",
&safe_command,
);
@@ -980,8 +980,14 @@ 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);
- let meta = dquotes > 0 || Preg::is_match(r"/%[^%]+%|![^!]+!/", &argument);
+ argument = Preg::replace5(
+ php_regex!(r#"/(\\*)"/"#),
+ r#"$1$1\""#,
+ &argument,
+ -1,
+ &mut dquotes,
+ );
+ let meta = dquotes > 0 || Preg::is_match(php_regex!(r"/%[^%]+%|![^!]+!/"), &argument);
if !meta && !quote {
quote = strpbrk(&argument, "^&|<>()").is_some();
@@ -992,8 +998,8 @@ impl ProcessExecutor {
}
if meta {
- argument = Preg::replace(r#"/(["^&|<>()%])/"#, "^$1", &argument);
- argument = Preg::replace(r"/(!)/", "^^$1", &argument);
+ argument = Preg::replace(php_regex!(r#"/(["^&|<>()%])/"#), "^$1", &argument);
+ argument = Preg::replace(php_regex!(r"/(!)/"), "^^$1", &argument);
}
argument
diff --git a/crates/shirabe/src/util/remote_filesystem.rs b/crates/shirabe/src/util/remote_filesystem.rs
index df47be20..9eaf8229 100644
--- a/crates/shirabe/src/util/remote_filesystem.rs
+++ b/crates/shirabe/src/util/remote_filesystem.rs
@@ -20,7 +20,7 @@ use shirabe_php_shim::{
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,
- parse_url, preg_quote, strpos, strtolower, strtr, substr, trim, zlib_decode,
+ parse_url, php_regex, preg_quote, strpos, strtolower, strtr, substr, trim, zlib_decode,
};
/// Result of `RemoteFilesystem::get` — string content, `true` (for copy), or `false`.
@@ -149,7 +149,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)) {
+ if Preg::is_match3(php_regex!("{^HTTP/\\S+ (\\d+)}i"), header, Some(&mut m)) {
value = m
.get(&CaptureKey::ByIndex(1))
.and_then(|s| s.parse().ok())
@@ -163,7 +163,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) {
+ if Preg::is_match(php_regex!("{^HTTP/\\S+ \\d+}i"), header) {
value = Some(header.clone());
}
}
@@ -287,8 +287,10 @@ impl RemoteFilesystem {
crate::io::DEBUG,
);
- if (!Preg::is_match("{^http://(repo\\.)?packagist\\.org/p/}", &file_url)
- || (strpos(&file_url, "$").is_none() && strpos(&file_url, "%24").is_none()))
+ if (!Preg::is_match(
+ php_regex!("{^http://(repo\\.)?packagist\\.org/p/}"),
+ &file_url,
+ ) || (strpos(&file_url, "$").is_none() && strpos(&file_url, "%24").is_none()))
&& !degraded_packagist
{
let _ = self.config.borrow_mut().prohibit_url_by_config(
@@ -472,7 +474,10 @@ impl RemoteFilesystem {
None,
) != ".zip")
&& content_type.is_some()
- && Preg::is_match("{^text/html\\b}i", content_type.as_deref().unwrap_or(""));
+ && Preg::is_match(
+ php_regex!("{^text/html\\b}i"),
+ content_type.as_deref().unwrap_or(""),
+ );
if bitbucket_login_match {
result = None;
if retry_auth_failure {
@@ -940,7 +945,7 @@ impl RemoteFilesystem {
.to_string();
target_url = Some(Preg::replace(
- &format!(
+ format!(
"{{^(.+(?://|@){}(?::\\d+)?)(?:[/\\?].*)?$}}",
preg_quote(&url_host, None)
),
@@ -949,7 +954,7 @@ impl RemoteFilesystem {
));
} else {
target_url = Some(Preg::replace(
- "{^(.+/)[^/?]*(?:\\?.*)?$}",
+ php_regex!("{^(.+/)[^/?]*(?:\\?.*)?$}"),
&format!("\\1{}", location_header),
&self.file_url,
));
diff --git a/crates/shirabe/src/util/svn.rs b/crates/shirabe/src/util/svn.rs
index 4c01a3ae..f761ac05 100644
--- a/crates/shirabe/src/util/svn.rs
+++ b/crates/shirabe/src/util/svn.rs
@@ -10,7 +10,7 @@ use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
LogicException, PHP_URL_HOST, PhpMixed, RuntimeException, empty, implode, parse_url,
- parse_url_all, stripos, strpos, trim,
+ parse_url_all, php_regex, stripos, strpos, trim,
};
use std::sync::Mutex;
@@ -444,7 +444,11 @@ impl Svn {
None,
) {
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(r"{(\d+(?:\.\d+)+)}", &output, Some(&mut matches)) {
+ if Preg::is_match3(
+ php_regex!(r"{(\d+(?:\.\d+)+)}"),
+ &output,
+ Some(&mut matches),
+ ) {
*cached = Some(
matches
.get(&CaptureKey::ByIndex(1))
diff --git a/crates/shirabe/src/util/tls_helper.rs b/crates/shirabe/src/util/tls_helper.rs
index 6422be3e..5121bd06 100644
--- a/crates/shirabe/src/util/tls_helper.rs
+++ b/crates/shirabe/src/util/tls_helper.rs
@@ -3,7 +3,7 @@
use shirabe_external_packages::composer::ca_bundle::ca_bundle::CaBundle;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{
- PhpMixed, ltrim, preg_quote, str_replace, strtolower, substr, substr_count,
+ PhpMixed, ltrim, php_regex, preg_quote, str_replace, strtolower, substr, substr_count,
};
/// Extracted certificate names. Mirrors PHP's `array{cn: string, san: string[]}`.
@@ -81,7 +81,7 @@ impl TlsHelper {
.and_then(|e| e.get("subjectAltName"))
.and_then(|s| s.as_string())
{
- let split = Preg::split("{\\s*,\\s*}", san);
+ let split = Preg::split(php_regex!("{\\s*,\\s*}"), san);
subject_alt_names = split
.into_iter()
.filter_map(|name| {
diff --git a/crates/shirabe/src/util/url.rs b/crates/shirabe/src/util/url.rs
index b1f17fb1..77649308 100644
--- a/crates/shirabe/src/util/url.rs
+++ b/crates/shirabe/src/util/url.rs
@@ -4,7 +4,7 @@ use crate::config::Config;
use crate::util::GitHub;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
-use shirabe_php_shim::{PHP_URL_HOST, PHP_URL_PORT, PhpMixed, in_array, parse_url};
+use shirabe_php_shim::{PHP_URL_HOST, PHP_URL_PORT, PhpMixed, in_array, parse_url, php_regex};
pub struct Url;
@@ -18,7 +18,9 @@ impl Url {
if host == "api.github.com" || host == "github.com" || host == "www.github.com" {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::match3(
- r"{^https?://(?:www\.)?github\.com/([^/]+)/([^/]+)/(zip|tar)ball/(.+)$}i",
+ php_regex!(
+ r"{^https?://(?:www\.)?github\.com/([^/]+)/([^/]+)/(zip|tar)ball/(.+)$}i"
+ ),
&url,
Some(&mut m),
) {
@@ -30,7 +32,9 @@ impl Url {
r#ref
);
} else if Preg::match3(
- r"{^https?://(?:www\.)?github\.com/([^/]+)/([^/]+)/archive/.+\.(zip|tar)(?:\.gz)?$}i",
+ php_regex!(
+ r"{^https?://(?:www\.)?github\.com/([^/]+)/([^/]+)/archive/.+\.(zip|tar)(?:\.gz)?$}i"
+ ),
&url,
Some(&mut m),
) {
@@ -42,7 +46,9 @@ impl Url {
r#ref
);
} else if Preg::match3(
- r"{^https?://api\.github\.com/repos/([^/]+)/([^/]+)/(zip|tar)ball(?:/.+)?$}i",
+ php_regex!(
+ r"{^https?://api\.github\.com/repos/([^/]+)/([^/]+)/(zip|tar)ball(?:/.+)?$}i"
+ ),
&url,
Some(&mut m),
) {
@@ -57,7 +63,9 @@ impl Url {
} else if host == "bitbucket.org" || host == "www.bitbucket.org" {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::match3(
- r"{^https?://(?:www\.)?bitbucket\.org/([^/]+)/([^/]+)/get/(.+)\.(zip|tar\.gz|tar\.bz2)$}i",
+ php_regex!(
+ r"{^https?://(?:www\.)?bitbucket\.org/([^/]+)/([^/]+)/get/(.+)\.(zip|tar\.gz|tar\.bz2)$}i"
+ ),
&url,
Some(&mut m),
) {
@@ -72,7 +80,9 @@ impl Url {
} else if host == "gitlab.com" || host == "www.gitlab.com" {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::match3(
- r"{^https?://(?:www\.)?gitlab\.com/api/v[34]/projects/([^/]+)/repository/archive\.(zip|tar\.gz|tar\.bz2|tar)\?sha=.+$}i",
+ php_regex!(
+ r"{^https?://(?:www\.)?gitlab\.com/api/v[34]/projects/([^/]+)/repository/archive\.(zip|tar\.gz|tar\.bz2|tar)\?sha=.+$}i"
+ ),
&url,
Some(&mut m),
) {
@@ -89,7 +99,7 @@ impl Url {
true,
) {
url = Preg::replace(
- r"{(/repos/[^/]+/[^/]+/(zip|tar)ball)(?:/.+)?$}i",
+ php_regex!(r"{(/repos/[^/]+/[^/]+/(zip|tar)ball)(?:/.+)?$}i"),
&format!("$1/{}", r#ref),
&url,
);
@@ -99,7 +109,9 @@ impl Url {
true,
) {
url = Preg::replace(
- r"{(/api/v[34]/projects/[^/]+/repository/archive\.(?:zip|tar\.gz|tar\.bz2|tar)\?sha=).+$}i",
+ php_regex!(
+ r"{(/api/v[34]/projects/[^/]+/repository/archive\.(?:zip|tar\.gz|tar\.bz2|tar)\?sha=).+$}i"
+ ),
&format!("${{1}}{}", r#ref),
&url,
);
@@ -164,10 +176,10 @@ 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);
+ let url = Preg::replace(php_regex!(r"{([&?]access_token=)[^&]+}"), "$1***", &url);
Preg::replace_callback(
- r"{^(?P<prefix>[a-z0-9]+://)?(?P<user>[^:/\s@]+):(?P<password>[^@\s/]+)@}i",
+ php_regex!(r"{^(?P<prefix>[a-z0-9]+://)?(?P<user>[^:/\s@]+):(?P<password>[^@\s/]+)@}i"),
|m| {
let user = m
.get(&CaptureKey::ByName("user".to_string()))