diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-18 01:57:02 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-18 01:57:02 +0900 |
| commit | e093b2be1c333e67c96aebb0a5291bea9ae3d6db (patch) | |
| tree | 0743fad689f419959c3a898605e21485087884fa /crates/shirabe/src/util | |
| parent | 050c56ef263d90d862ef565bc1762909110e02eb (diff) | |
| download | php-shirabe-e093b2be1c333e67c96aebb0a5291bea9ae3d6db.tar.gz php-shirabe-e093b2be1c333e67c96aebb0a5291bea9ae3d6db.tar.zst php-shirabe-e093b2be1c333e67c96aebb0a5291bea9ae3d6db.zip | |
refactor(preg): drop the offset argument from preg_match
Every call site but one passed offset 0. The remaining one, the UTF-8
chunking loop in Application, slices the subject instead: its pattern has
no anchor or lookaround, so matching a suffix is equivalent to starting
the search at that offset.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/util')
| -rw-r--r-- | crates/shirabe/src/util/auth_helper.rs | 4 | ||||
| -rw-r--r-- | crates/shirabe/src/util/composer_mirror.rs | 10 | ||||
| -rw-r--r-- | crates/shirabe/src/util/config_validator.rs | 11 | ||||
| -rw-r--r-- | crates/shirabe/src/util/filesystem.rs | 19 | ||||
| -rw-r--r-- | crates/shirabe/src/util/forgejo_url.rs | 4 | ||||
| -rw-r--r-- | crates/shirabe/src/util/git.rs | 51 | ||||
| -rw-r--r-- | crates/shirabe/src/util/github.rs | 14 | ||||
| -rw-r--r-- | crates/shirabe/src/util/hg.rs | 8 | ||||
| -rw-r--r-- | crates/shirabe/src/util/http/curl_downloader.rs | 7 | ||||
| -rw-r--r-- | crates/shirabe/src/util/http/response.rs | 6 | ||||
| -rw-r--r-- | crates/shirabe/src/util/http_downloader.rs | 10 | ||||
| -rw-r--r-- | crates/shirabe/src/util/platform.rs | 4 | ||||
| -rw-r--r-- | crates/shirabe/src/util/process_executor.rs | 14 | ||||
| -rw-r--r-- | crates/shirabe/src/util/remote_filesystem.rs | 12 | ||||
| -rw-r--r-- | crates/shirabe/src/util/svn.rs | 6 | ||||
| -rw-r--r-- | crates/shirabe/src/util/url.rs | 29 |
16 files changed, 81 insertions, 128 deletions
diff --git a/crates/shirabe/src/util/auth_helper.rs b/crates/shirabe/src/util/auth_helper.rs index 8d35d817..3da49258 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_match2, str_replace, strpos, + is_string, json_decode_assoc, parse_url, php_regex, preg_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_match2(php_regex!(r"{^https?://api\.github\.com/}"), url, 0).is_some() { + if preg_match(php_regex!(r"{^https?://api\.github\.com/}"), url).is_some() { 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 78f38782..0fb38716 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_match2, preg_replace}; +use shirabe_php_shim::{hash, php_regex, 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_match2(php_regex!(r"{^([a-f0-9]*|%reference%)$}"), r, 0).is_some() { + if preg_match(php_regex!(r"{^([a-f0-9]*|%reference%)$}"), r).is_some() { r.to_string() } else { hash("md5", r) @@ -52,22 +52,20 @@ impl ComposerMirror { url: &str, r#type: Option<&str>, ) -> String { - let normalized_url = if let Some(gh_matches) = preg_match2( + let normalized_url = if let Some(gh_matches) = preg_match( php_regex!( r"#^(?:(?:https?|git)://github\.com/|git@github\.com:)([^/]+)/(.+?)(?:\.git)?$#" ), url, - 0, ) { format!( "gh-{}/{}", gh_matches.get(1).unwrap_or_default(), gh_matches.get(2).unwrap_or_default(), ) - } else if let Some(bb_matches) = preg_match2( + } else if let Some(bb_matches) = preg_match( php_regex!(r"#^https://bitbucket\.org/([^/]+)/(.+?)(?:\.git)?/?$#"), url, - 0, ) { format!( "bb-{}/{}", diff --git a/crates/shirabe/src/util/config_validator.rs b/crates/shirabe/src/util/config_validator.rs index 52560caa..e9282a9f 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_match2, preg_replace}; +use shirabe_php_shim::{PhpMixed, php_regex, preg_match, preg_replace}; use shirabe_spdx_licenses::SpdxLicenses; #[derive(Debug)] @@ -117,15 +117,14 @@ 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_match2(php_regex!(r"{^[AL]?GPL-[123](\.[01])?\+$}i"), license, 0) - .is_some() + if preg_match(php_regex!(r"{^[AL]?GPL-[123](\.[01])?\+$}i"), license).is_some() { warnings.push(format!( "License \"{}\" is a deprecated SPDX license identifier, use \"{}-or-later\" instead", license, license.replace('+', "") )); - } else if preg_match2(php_regex!(r"{^[AL]?GPL-[123](\.[01])?$}i"), license, 0) + } else if preg_match(php_regex!(r"{^[AL]?GPL-[123](\.[01])?$}i"), license) .is_some() { warnings.push(format!( @@ -148,7 +147,7 @@ impl ConfigValidator { if let Some(PhpMixed::String(name)) = manifest.get("name") && !name.is_empty() - && preg_match2(php_regex!(r"{[A-Z]}"), name, 0).is_some() + && preg_match(php_regex!(r"{[A-Z]}"), name).is_some() { let suggest_name = preg_replace( php_regex!(r"{(?:([a-z])([A-Z])|([A-Z])([A-Z][a-z]))}"), @@ -225,7 +224,7 @@ impl ConfigValidator { packages.extend(require_dev); for (package, version) in &packages { if let PhpMixed::String(version_str) = version - && preg_match2(php_regex!(r"{#}"), version_str, 0).is_some() + && preg_match(php_regex!(r"{#}"), version_str).is_some() { 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 b79beeae..ae19a998 100644 --- a/crates/shirabe/src/util/filesystem.rs +++ b/crates/shirabe/src/util/filesystem.rs @@ -8,7 +8,7 @@ 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_match2, preg_replace, preg_replace_callback, rename, rmdir, rtrim, str_repeat, + 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, }; @@ -246,7 +246,7 @@ impl Filesystem { return Ok(Some(true)); } - if preg_match2(php_regex!("{^(?:[a-z]:)?[/\\\\]+$}i"), directory, 0).is_some() { + if preg_match(php_regex!("{^(?:[a-z]:)?[/\\\\]+$}i"), directory).is_some() { 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_match2(php_regex!("{^[A-Z]:/?$}i"), &common_path, 0).is_none() + && preg_match(php_regex!("{^[A-Z]:/?$}i"), &common_path).is_none() { 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_match2(php_regex!("{^[A-Z]:/?$}i"), &common_path, 0).is_none() + && preg_match(php_regex!("{^[A-Z]:/?$}i"), &common_path).is_none() && "." != common_path { common_path = strtr(&dirname(&common_path), "\\", "/"); @@ -735,10 +735,9 @@ impl Filesystem { } // extract a prefix being a protocol://, protocol:, protocol://drive: or simply drive: - if let Some(prefix_match) = preg_match2( + if let Some(prefix_match) = preg_match( php_regex!("{^( [0-9a-z]{2,}+: (?: // (?: [a-z]: )? )? | [a-z]: )}ix"), &path, - 0, ) { prefix = prefix_match.get(1).unwrap_or_default().to_string(); path = substr(&path, strlen(&prefix), None); @@ -779,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_match2(php_regex!("{^[/\\\\]+$}"), &path, 0).is_none() { + if preg_match(php_regex!("{^[/\\\\]+$}"), &path).is_none() { path = rtrim(&path, Some("/\\")); } @@ -791,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_match2( + return preg_match( php_regex!( "{^(file://(?!//)|/(?!/)|/?[a-z]:[\\\\/]|\\.\\.[\\\\/]|[a-z0-9_.-]+[\\\\/])}i" ), path, - 0, ) .is_some(); } - preg_match2( + preg_match( php_regex!("{^(file://|/|/?[a-z]:[\\\\/]|\\.\\.[\\\\/]|[a-z0-9_.-]+[\\\\/])}i"), path, - 0, ) .is_some() } diff --git a/crates/shirabe/src/util/forgejo_url.rs b/crates/shirabe/src/util/forgejo_url.rs index abb39d88..3aa32113 100644 --- a/crates/shirabe/src/util/forgejo_url.rs +++ b/crates/shirabe/src/util/forgejo_url.rs @@ -1,6 +1,6 @@ //! ref: composer/src/Composer/Util/ForgejoUrl.php -use shirabe_php_shim::{InvalidArgumentException, preg_match2}; +use shirabe_php_shim::{InvalidArgumentException, preg_match}; #[derive(Debug)] pub struct ForgejoUrl { @@ -36,7 +36,7 @@ impl ForgejoUrl { pub fn try_from(repo_url: Option<&str>) -> Option<Self> { let repo_url = repo_url?; - let matches = preg_match2(Self::URL_REGEX, repo_url, 0)?; + let matches = preg_match(Self::URL_REGEX, repo_url)?; let m: Vec<String> = (0..5) .map(|i| matches.get(i).unwrap_or_default().to_string()) diff --git a/crates/shirabe/src/util/git.rs b/crates/shirabe/src/util/git.rs index 31771e6c..2426780f 100644 --- a/crates/shirabe/src/util/git.rs +++ b/crates/shirabe/src/util/git.rs @@ -17,7 +17,7 @@ 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_match2, preg_quote, preg_replace, rawurldecode, rawurlencode, + is_dir, php_regex, 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_match2(php_regex!(r"{^ssh://[^@]+@[^:]+:[^0-9]+}"), url, 0).is_some() { + if preg_match(php_regex!(r"{^ssh://[^@]+@[^:]+:[^0-9]+}"), url).is_some() { 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 @@ -225,10 +225,9 @@ impl Git { &mut output, cwd, )?; - if let Some(m) = preg_match2( + if let Some(m) = preg_match( php_regex!(r"{^(?:composer|origin)\s+https?://(.+):(.+)@([^/]+)}im"), &output, - 0, ) { let m3 = m.get(3).unwrap_or_default().to_string(); if !self.io.has_authentication(&m3) { @@ -244,13 +243,12 @@ impl Git { let protocols = self.config.borrow_mut().get("github-protocols"); // public github, autoswitch protocols // @phpstan-ignore composerPcre.maybeUnsafeStrictGroups - if let Some(m) = preg_match2( + if let Some(m) = preg_match( format!( "{{^(?:https?|git)://{}/(.*)}}", Self::get_github_domains_regex(&self.config.borrow()) ), url, - 0, ) { let mut messages: Vec<String> = vec![]; let protocols_list: Vec<String> = match &protocols { @@ -312,13 +310,12 @@ impl Git { .collect(), _ => vec![], }; - let bypass_ssh_for_github = preg_match2( + let bypass_ssh_for_github = preg_match( format!( "{{^git@{}:(.+?)\\.git$}}i", Self::get_github_domains_regex(&self.config.borrow()) ), url, - 0, ) .is_some() && !in_array_strict( @@ -342,22 +339,20 @@ impl Git { let mut error_msg = self.process.borrow().get_error_output().to_string(); // private github repository without ssh key access, try https with auth // @phpstan-ignore composerPcre.maybeUnsafeStrictGroups - let github_matched = preg_match2( + let github_matched = preg_match( format!( "{{^git@{}:(.+?)\\.git$}}i", Self::get_github_domains_regex(&self.config.borrow()) ), url, - 0, ) .or_else(|| { - preg_match2( + preg_match( format!( "{{^https?://{}/(.*?)(?:\\.git)?$}}i", Self::get_github_domains_regex(&self.config.borrow()) ), url, - 0, ) }); if let Some(m) = github_matched { @@ -410,18 +405,12 @@ impl Git { credentials = vec![rawurlencode(&username), rawurlencode(&password)]; error_msg = self.process.borrow().get_error_output().to_string(); } - } else if let Some(m) = preg_match2( + } else if let Some(m) = preg_match( php_regex!(r"{^(https?)://(bitbucket\.org)/(.*?)(?:\.git)?$}i"), url, - 0, ) - .or_else(|| { - preg_match2( - php_regex!(r"{^(git)@(bitbucket\.org):(.+?\.git)$}i"), - url, - 0, - ) - }) { + .or_else(|| preg_match(php_regex!(r"{^(git)@(bitbucket\.org):(.+?\.git)$}i"), url)) + { // bitbucket either through oauth or app password, with fallback to ssh. let mut bitbucket_util = Bitbucket::new( self.io.clone(), @@ -558,22 +547,20 @@ impl Git { } error_msg = self.process.borrow().get_error_output().to_string(); - } else if let Some(m) = preg_match2( + } else if let Some(m) = preg_match( format!( "{{^(git)@{}:(.+?\\.git)$}}i", Self::get_gitlab_domains_regex(&self.config.borrow()) ), url, - 0, ) .or_else(|| { - preg_match2( + preg_match( format!( "{{^(https?)://{}/(.*)}}i", Self::get_gitlab_domains_regex(&self.config.borrow()) ), url, - 0, ) }) { let mut m1 = m.get(1).unwrap_or_default().to_string(); @@ -928,7 +915,7 @@ impl Git { pretty_version: Option<&str>, ) -> anyhow::Result<bool> { if self.check_ref_is_in_mirror(dir, r#ref)? { - if preg_match2(php_regex!(r"{^[a-f0-9]{40}$}"), r#ref, 0).is_some() + if preg_match(php_regex!(r"{^[a-f0-9]{40}$}"), r#ref).is_some() && let Some(pretty_version) = pretty_version { let branch = preg_replace( @@ -962,17 +949,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_match2( + && preg_match( format!(r"{{^[\s*]*v?{}$}}m", preg_quote(&branch, None)), branches.as_deref().unwrap_or(""), - 0, ) .is_none() && tags.is_some() - && preg_match2( + && preg_match( format!(r"{{^[\s*]*{}$}}m", preg_quote(&branch, None)), tags.as_deref().unwrap_or(""), - 0, ) .is_none() { @@ -1099,7 +1084,7 @@ impl Git { } fn get_authentication_failure<'u>(&self, url: &'u str) -> Option<PregMatches<'u>> { - let m = preg_match2(php_regex!(r"{^(https?://)([^/]+)(.*)$}i"), url, 0)?; + let m = preg_match(php_regex!(r"{^(https?://)([^/]+)(.*)$}i"), url)?; let auth_failures = [ "fatal: Authentication failed", @@ -1182,7 +1167,7 @@ impl Git { .split_lines(output_mixed.as_string().unwrap_or("")); for line in lines { if let Some(matches) = - preg_match2(php_regex!(r"{^\s*HEAD branch:\s(.+)\s*$}m"), &line, 0) + preg_match(php_regex!(r"{^\s*HEAD branch:\s(.+)\s*$}m"), &line) { return Ok(Some(matches.get(1).unwrap_or_default().to_string())); } @@ -1303,7 +1288,7 @@ impl Git { ); if exit_code == 0 && let Some(matches) = - preg_match2(php_regex!(r"/^git version (\d+(?:\.\d+)+)/m"), &output, 0) + preg_match(php_regex!(r"/^git version (\d+(?:\.\d+)+)/m"), &output) { *version = Some(matches.get(1).map(str::to_string)); } diff --git a/crates/shirabe/src/util/github.rs b/crates/shirabe/src/util/github.rs index 9d73ae84..a50f928a 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_match2, stripos, strtolower, + PhpMixed, date_local, in_array_loose, php_regex, preg_match, stripos, strtolower, }; #[derive(Debug)] @@ -326,7 +326,7 @@ impl GitHub { if stripos(header, "x-github-sso: required").is_none() { continue; } - if let Some(caps) = preg_match2(php_regex!(r"{\burl=(?P<url>[^\s;]+)}"), header, 0) { + if let Some(caps) = preg_match(php_regex!(r"{\burl=(?P<url>[^\s;]+)}"), header) { return caps.name("url").map(str::to_string); } } @@ -336,13 +336,7 @@ impl GitHub { pub fn is_rate_limited(&self, headers: &[String]) -> bool { for header in headers { - if preg_match2( - php_regex!(r"{^x-ratelimit-remaining: *0$}i"), - header.trim(), - 0, - ) - .is_some() - { + if preg_match(php_regex!(r"{^x-ratelimit-remaining: *0$}i"), header.trim()).is_some() { return true; } } @@ -352,7 +346,7 @@ impl GitHub { pub fn requires_sso(&self, headers: &[String]) -> bool { for header in headers { - if preg_match2(php_regex!(r"{^x-github-sso: required}i"), header.trim(), 0).is_some() { + if preg_match(php_regex!(r"{^x-github-sso: required}i"), header.trim()).is_some() { return true; } } diff --git a/crates/shirabe/src/util/hg.rs b/crates/shirabe/src/util/hg.rs index 00fee240..3180f4f9 100644 --- a/crates/shirabe/src/util/hg.rs +++ b/crates/shirabe/src/util/hg.rs @@ -5,7 +5,7 @@ use crate::io::IOInterface; use crate::io::IOInterfaceImmutable; use crate::util::ProcessExecutor; use crate::util::Url; -use shirabe_php_shim::{php_regex, preg_match2, rawurlencode}; +use shirabe_php_shim::{php_regex, preg_match, rawurlencode}; use std::sync::OnceLock; static VERSION: OnceLock<Option<String>> = OnceLock::new(); @@ -55,12 +55,11 @@ impl Hg { } // Try with the authentication information available - let matched = preg_match2( + let matched = preg_match( php_regex!( r"{^(?P<proto>ssh|https?)://(?:(?P<user>[^:@]+)(?::(?P<pass>[^:@]+))?@)?(?P<host>[^/]+)(?P<path>/.*)?}mi" ), &url, - 0, ); if let Some(matches) = matched @@ -151,10 +150,9 @@ impl Hg { &mut output, None, ) == 0 - && let Some(matches) = preg_match2( + && let Some(matches) = preg_match( php_regex!(r"/^.+? (\d+(?:\.\d+)+)(?:\+.*?)?\)?\r?\n/"), &output, - 0, ) { return matches.get(1).map(str::to_string); diff --git a/crates/shirabe/src/util/http/curl_downloader.rs b/crates/shirabe/src/util/http/curl_downloader.rs index 91165015..6754f784 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_match2, preg_quote, + PhpMixed, in_array_loose, in_array_strict, parse_url, php_regex, preg_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_match2(php_regex!(r"{^http://(repo\.)?packagist\.org/p/}"), url, 0).is_none() + if preg_match(php_regex!(r"{^http://(repo\.)?packagist\.org/p/}"), url).is_none() || (strpos(url, "$").is_none() && strpos(url, "%24").is_none()) { self.config.borrow_mut().prohibit_url_by_config( @@ -746,13 +746,12 @@ impl CurlDownloader { && substr(url, -4, None) == ".zip" && (location_header.is_none() || substr(location_header.as_deref().unwrap_or(""), -4, None) != ".zip") - && preg_match2( + && preg_match( php_regex!(r"{^text/html\b}i"), &response .inner .get_header("content-type") .unwrap_or_default(), - 0, ) .is_some() { diff --git a/crates/shirabe/src/util/http/response.rs b/crates/shirabe/src/util/http/response.rs index ed5c5214..6fe95200 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_match2, preg_quote}; +use shirabe_php_shim::{PhpMixed, php_regex, 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_match2(php_regex!(r"{^HTTP/\S+ \d+}i"), header, 0).is_some() { + if preg_match(php_regex!(r"{^HTTP/\S+ \d+}i"), header).is_some() { // 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()); @@ -64,7 +64,7 @@ impl Response { let mut value = None; let pattern = format!("{{^{}:\\s*(.+?)\\s*$}}i", preg_quote(name, None)); for header in headers { - if let Some(matches) = preg_match2(&pattern, header, 0) + if let Some(matches) = preg_match(&pattern, header) && let Some(s) = matches.get(1) { value = Some(s.to_string()); diff --git a/crates/shirabe/src/util/http_downloader.rs b/crates/shirabe/src/util/http_downloader.rs index 8210a5c4..f022ef4e 100644 --- a/crates/shirabe/src/util/http_downloader.rs +++ b/crates/shirabe/src/util/http_downloader.rs @@ -19,7 +19,7 @@ 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_match2, preg_replace, + file_get_contents, function_exists, implode, is_numeric, php_regex, preg_match, preg_replace, rawurldecode, stream_context_create, stripos, strpos, substr, ucfirst, }; use shirabe_semver::constraint::SimpleConstraint; @@ -239,11 +239,7 @@ impl HttpDownloader { let origin = Url::get_origin(&self.config.borrow(), url); // capture username/password from URL if there is one - if let Some(m) = preg_match2( - php_regex!(r"{^https?://([^:/]+):([^@/]+)@([^/]+)}i"), - url, - 0, - ) { + if let Some(m) = preg_match(php_regex!(r"{^https?://([^:/]+):([^@/]+)@([^/]+)}i"), url) { self.io.borrow_mut().set_authentication( origin.clone(), rawurldecode(m.get(1).unwrap_or_default().to_string().as_str()), @@ -489,7 +485,7 @@ impl HttpDownloader { return false; } - if preg_match2(php_regex!(r"{^https?://}i"), url, 0).is_none() { + if preg_match(php_regex!(r"{^https?://}i"), url).is_none() { return false; } diff --git a/crates/shirabe/src/util/platform.rs b/crates/shirabe/src/util/platform.rs index 91039c17..3daf17c6 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_match2, preg_replace_callback, putenv, putenv_clear, realpath, stream_isatty, stripos, + preg_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_match2(php_regex!(r"#^~[\\/]#"), path, 0).is_some() { + if preg_match(php_regex!(r"#^~[\\/]#"), path).is_some() { 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 158729b4..64082064 100644 --- a/crates/shirabe/src/util/process_executor.rs +++ b/crates/shirabe/src/util/process_executor.rs @@ -11,7 +11,7 @@ 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_match2, preg_replace, preg_replace_callback, preg_replace2, preg_split, rtrim, + 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, }; use shirabe_symfony_process::ExecutableFinder; @@ -216,7 +216,7 @@ impl ProcessExecutor { if is_string(&command) { let mut command_str = command.as_string().unwrap_or("").to_string(); if Platform::is_windows() - && let Some(m) = preg_match2(php_regex!(r"{^([^:/\\]++) }"), &command_str, 0) + && let Some(m) = preg_match(php_regex!(r"{^([^:/\\]++) }"), &command_str) { let m1 = m.get(1).unwrap_or_default().to_string(); command_str = substr_replace( @@ -832,18 +832,15 @@ 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_match2( + if preg_match( GitHub::GITHUB_TOKEN_REGEX, m.name("user").unwrap_or_default(), - 0, ) .is_some() { return Ok("://***:***@".to_string()); } - if preg_match2(r"{^[a-f0-9]{12,}$}", m.name("user").unwrap_or_default(), 0) - .is_some() - { + if preg_match(r"{^[a-f0-9]{12,}$}", m.name("user").unwrap_or_default()).is_some() { return Ok("://***:***@".to_string()); } @@ -906,8 +903,7 @@ impl ProcessExecutor { -1, Some(&mut dquotes), ); - let meta = - dquotes > 0 || preg_match2(php_regex!(r"/%[^%]+%|![^!]+!/"), &argument, 0).is_some(); + let meta = dquotes > 0 || preg_match(php_regex!(r"/%[^%]+%|![^!]+!/"), &argument).is_some(); 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 7af5473a..a7901567 100644 --- a/crates/shirabe/src/util/remote_filesystem.rs +++ b/crates/shirabe/src/util/remote_filesystem.rs @@ -19,7 +19,7 @@ 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_match2, preg_quote, preg_replace, strpos, strtolower, strtr, substr, + parse_url, php_regex, preg_match, preg_quote, preg_replace, strpos, strtolower, strtr, substr, trim, zlib_decode, }; @@ -148,7 +148,7 @@ impl RemoteFilesystem { pub fn find_status_code(headers: &[String]) -> Option<i64> { let mut value: Option<i64> = None; for header in headers { - if let Some(m) = preg_match2(php_regex!("{^HTTP/\\S+ (\\d+)}i"), header, 0) { + if let Some(m) = preg_match(php_regex!("{^HTTP/\\S+ (\\d+)}i"), header) { value = m.get(1).and_then(|s| s.parse().ok()).or(Some(0)); } } @@ -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_match2(php_regex!("{^HTTP/\\S+ \\d+}i"), header, 0).is_some() { + if preg_match(php_regex!("{^HTTP/\\S+ \\d+}i"), header).is_some() { value = Some(header.clone()); } } @@ -285,10 +285,9 @@ impl RemoteFilesystem { crate::io::DEBUG, ); - if (preg_match2( + if (preg_match( php_regex!("{^http://(repo\\.)?packagist\\.org/p/}"), &file_url, - 0, ) .is_none() || (strpos(&file_url, "$").is_none() && strpos(&file_url, "%24").is_none())) @@ -475,10 +474,9 @@ impl RemoteFilesystem { None, ) != ".zip") && content_type.is_some() - && preg_match2( + && preg_match( php_regex!("{^text/html\\b}i"), content_type.as_deref().unwrap_or(""), - 0, ) .is_some(); if bitbucket_login_match { diff --git a/crates/shirabe/src/util/svn.rs b/crates/shirabe/src/util/svn.rs index 38189d31..b4f53470 100644 --- a/crates/shirabe/src/util/svn.rs +++ b/crates/shirabe/src/util/svn.rs @@ -7,8 +7,8 @@ use crate::io::io_interface; use crate::util::Platform; use crate::util::ProcessExecutor; use shirabe_php_shim::{ - LogicException, PhpMixed, RuntimeException, implode, parse_url, php_regex, preg_match2, - stripos, strpos, trim, + LogicException, PhpMixed, RuntimeException, implode, parse_url, php_regex, preg_match, stripos, + strpos, trim, }; use std::sync::Mutex; @@ -404,7 +404,7 @@ impl Svn { &["svn".to_string(), "--version".to_string()], &mut output, None, - ) && let Some(matches) = preg_match2(php_regex!(r"{(\d+(?:\.\d+)+)}"), &output, 0) + ) && let Some(matches) = preg_match(php_regex!(r"{(\d+(?:\.\d+)+)}"), &output) { *cached = Some(matches.get(1).unwrap_or_default().to_string()); } diff --git a/crates/shirabe/src/util/url.rs b/crates/shirabe/src/util/url.rs index 2754ef09..75841167 100644 --- a/crates/shirabe/src/util/url.rs +++ b/crates/shirabe/src/util/url.rs @@ -3,7 +3,7 @@ use crate::config::Config; use crate::util::GitHub; use shirabe_php_shim::{ - PhpMixed, in_array_strict, parse_url, php_regex, preg_match2, preg_replace, + PhpMixed, in_array_strict, parse_url, php_regex, preg_match, preg_replace, preg_replace_callback, }; @@ -16,12 +16,11 @@ impl Url { .unwrap_or_default(); if host == "api.github.com" || host == "github.com" || host == "www.github.com" { - if let Some(m) = preg_match2( + if let Some(m) = preg_match( php_regex!( r"{^https?://(?:www\.)?github\.com/([^/]+)/([^/]+)/(zip|tar)ball/(.+)$}i" ), &url, - 0, ) { url = format!( "https://api.github.com/repos/{}/{}/{}ball/{}", @@ -30,12 +29,11 @@ impl Url { m.get(3).unwrap_or_default(), r#ref ); - } else if let Some(m) = preg_match2( + } else if let Some(m) = preg_match( php_regex!( r"{^https?://(?:www\.)?github\.com/([^/]+)/([^/]+)/archive/.+\.(zip|tar)(?:\.gz)?$}i" ), &url, - 0, ) { url = format!( "https://api.github.com/repos/{}/{}/{}ball/{}", @@ -44,12 +42,11 @@ impl Url { m.get(3).unwrap_or_default(), r#ref ); - } else if let Some(m) = preg_match2( + } else if let Some(m) = preg_match( php_regex!( r"{^https?://api\.github\.com/repos/([^/]+)/([^/]+)/(zip|tar)ball(?:/.+)?$}i" ), &url, - 0, ) { url = format!( "https://api.github.com/repos/{}/{}/{}ball/{}", @@ -60,12 +57,11 @@ impl Url { ); } } else if host == "bitbucket.org" || host == "www.bitbucket.org" { - if let Some(m) = preg_match2( + if let Some(m) = preg_match( php_regex!( r"{^https?://(?:www\.)?bitbucket\.org/([^/]+)/([^/]+)/get/(.+)\.(zip|tar\.gz|tar\.bz2)$}i" ), &url, - 0, ) { url = format!( "https://bitbucket.org/{}/{}/get/{}.{}", @@ -76,12 +72,11 @@ impl Url { ); } } else if host == "gitlab.com" || host == "www.gitlab.com" { - if let Some(m) = preg_match2( + if let Some(m) = preg_match( php_regex!( r"{^https?://(?:www\.)?gitlab\.com/api/v[34]/projects/([^/]+)/repository/archive\.(zip|tar\.gz|tar\.bz2|tar)\?sha=.+$}i" ), &url, - 0, ) { url = format!( "https://gitlab.com/api/v4/projects/{}/repository/archive.{}?sha={}", @@ -173,13 +168,11 @@ impl Url { let user = m.name("user").unwrap_or_default().to_string(); let prefix = m.name("prefix").unwrap_or_default().to_string(); // if the username looks like a long (12char+) hex string, or a modern github token (e.g. ghp_xxx, github_pat_xxx) we obfuscate that - Ok( - if preg_match2(GitHub::GITHUB_TOKEN_REGEX, &user, 0).is_some() { - format!("{}***:***@", prefix) - } else { - format!("{}{}:***@", prefix, user) - }, - ) + Ok(if preg_match(GitHub::GITHUB_TOKEN_REGEX, &user).is_some() { + format!("{}***:***@", prefix) + } else { + format!("{}{}:***@", prefix, user) + }) }, &url, ) |
