diff options
Diffstat (limited to 'crates')
90 files changed, 428 insertions, 627 deletions
diff --git a/crates/shirabe-class-map-generator/src/class_map.rs b/crates/shirabe-class-map-generator/src/class_map.rs index 982d8494..1d980129 100644 --- a/crates/shirabe-class-map-generator/src/class_map.rs +++ b/crates/shirabe-class-map-generator/src/class_map.rs @@ -1,7 +1,7 @@ //! ref: composer/vendor/composer/class-map-generator/src/ClassMap.php use indexmap::IndexMap; -use shirabe_php_shim::{OutOfBoundsException, preg_match2, rtrim, strpos, strtr}; +use shirabe_php_shim::{OutOfBoundsException, preg_match, rtrim, strpos, strtr}; #[derive(Debug, Clone)] pub struct PsrViolationEntry { @@ -66,7 +66,7 @@ impl ClassMap { for (class, paths) in &self.ambiguous_classes { let paths: Vec<String> = paths .iter() - .filter(|path| preg_match2(duplicates_filter, &strtr(path, "\\", "/"), 0).is_none()) + .filter(|path| preg_match(duplicates_filter, &strtr(path, "\\", "/")).is_none()) .cloned() .collect(); if !paths.is_empty() { diff --git a/crates/shirabe-class-map-generator/src/class_map_generator.rs b/crates/shirabe-class-map-generator/src/class_map_generator.rs index c4130cff..da2f62c5 100644 --- a/crates/shirabe-class-map-generator/src/class_map_generator.rs +++ b/crates/shirabe-class-map-generator/src/class_map_generator.rs @@ -5,7 +5,7 @@ use crate::file_list::FileList; use crate::php_file_parser::PhpFileParser; use shirabe_php_shim::{ InvalidArgumentException, LogicException, PATHINFO_EXTENSION, RuntimeException, explode, - getcwd, implode, is_dir, is_file, pathinfo, php_regex, preg_match2, preg_quote, preg_replace, + getcwd, implode, is_dir, is_file, pathinfo, php_regex, preg_match, preg_quote, preg_replace, preg_replace_callback, realpath, str_replace, stream_get_wrappers, strlen, strpos, strrpos, strtr, substr, }; @@ -135,7 +135,7 @@ impl ClassMapGenerator { } let is_stream_wrapper_path = - preg_match2(&self.stream_wrappers_regex, &file_path, 0).is_some(); + preg_match(&self.stream_wrappers_regex, &file_path).is_some(); if !Self::is_absolute_path(&file_path) && !is_stream_wrapper_path { file_path = format!("{}/{}", cwd, file_path); file_path = Self::normalize_path(&file_path); @@ -183,11 +183,11 @@ impl ClassMapGenerator { // check the realpath of the file against the excluded paths as the path might be a symlink and the excluded path is realpath'd so symlink are resolved if let Some(ref excluded) = excluded { - if preg_match2(excluded, &strtr(&real_path, "\\", "/"), 0).is_some() { + if preg_match(excluded, &strtr(&real_path, "\\", "/")).is_some() { continue; } // check non-realpath of file for directories symlink in project dir - if preg_match2(excluded, &strtr(&file_path, "\\", "/"), 0).is_some() { + if preg_match(excluded, &strtr(&file_path, "\\", "/")).is_some() { continue; } } @@ -348,10 +348,9 @@ impl ClassMapGenerator { } // extract a prefix being a protocol://, protocol:, protocol://drive: or simply drive: - if let Some(r#match) = preg_match2( + if let Some(r#match) = preg_match( php_regex!(r"{^( [0-9a-z]{2,}+: (?: // (?: [a-z]: )? )? | [a-z]: )}ix"), &path, - 0, ) { prefix = r#match.get(1).unwrap_or_default().to_string(); path = substr(&path, strlen(&prefix), None); diff --git a/crates/shirabe-php-shim/src/preg.rs b/crates/shirabe-php-shim/src/preg.rs index 6dc9cd43..d36d61c7 100644 --- a/crates/shirabe-php-shim/src/preg.rs +++ b/crates/shirabe-php-shim/src/preg.rs @@ -151,18 +151,9 @@ pub fn preg_quote(str: &str, delimiter: Option<char>) -> String { // Returns None if the pattern did not match; otherwise the match's capture groups. pub fn preg_match<'h>(pattern: impl PregPattern, subject: &'h str) -> Option<PregMatches<'h>> { - preg_match2(pattern, subject, 0) -} - -// `preg_match` with PHP's `$offset` argument: the search starts at byte offset `offset`. -pub fn preg_match2<'h>( - pattern: impl PregPattern, - subject: &'h str, - offset: usize, -) -> Option<PregMatches<'h>> { let __resolved = pattern.resolve(); let re = __resolved.regex(); - let caps = re.captures_at(subject, offset)?; + let caps = re.captures(subject)?; Some(PregMatches::new(caps)) } diff --git a/crates/shirabe-symfony-console/src/helper/table.rs b/crates/shirabe-symfony-console/src/helper/table.rs index acfcbfef..777f44c7 100644 --- a/crates/shirabe-symfony-console/src/helper/table.rs +++ b/crates/shirabe-symfony-console/src/helper/table.rs @@ -8,7 +8,7 @@ use crate::helper::{ }; use crate::output::OutputInterface; use indexmap::IndexMap; -use shirabe_php_shim::{PhpMixed, php_regex, preg_match2}; +use shirabe_php_shim::{PhpMixed, php_regex, preg_match}; /// A single cell within a table row. /// @@ -655,10 +655,9 @@ impl Table { let mut cell_format = cell_format; let mut pad_type = style.get_pad_type(); if cell.is_table_cell() && cell.style().is_some() { - let is_not_styled_by_tag = preg_match2( + let is_not_styled_by_tag = preg_match( php_regex!("/^<(\\w+|(\\w+=[\\w,]+;?)*)>.+<\\/(\\w+|(\\w+=\\w+;?)*)?>$/"), &cell_str, - 0, ) .is_none(); if is_not_styled_by_tag { diff --git a/crates/shirabe-symfony-finder/src/finder.rs b/crates/shirabe-symfony-finder/src/finder.rs index 5befed2d..b32418db 100644 --- a/crates/shirabe-symfony-finder/src/finder.rs +++ b/crates/shirabe-symfony-finder/src/finder.rs @@ -9,7 +9,7 @@ use crate::glob::Glob; use chrono::{NaiveDate, NaiveDateTime}; use indexmap::IndexSet; -use shirabe_php_shim::{file_exists, glob, is_dir, php_regex, preg_match2, preg_quote, rtrim}; +use shirabe_php_shim::{file_exists, glob, is_dir, php_regex, preg_match, preg_quote, rtrim}; use std::path::{Path, PathBuf}; use std::time::UNIX_EPOCH; @@ -310,7 +310,7 @@ impl Finder { let dir = rtrim(dir, Some("/")); - if preg_match2(php_regex!("#^(ssh2\\.)?s?ftp://#"), &dir, 0).is_some() { + if preg_match(php_regex!("#^(ssh2\\.)?s?ftp://#"), &dir).is_some() { format!("{dir}/") } else { dir @@ -591,7 +591,7 @@ fn exclude_accept( }; let path = path.replace('\\', "/"); - return preg_match2(pattern, &path, 0).is_none(); + return preg_match(pattern, &path).is_none(); } true @@ -618,14 +618,14 @@ fn to_regex_path(pattern: &str) -> String { /// `MultiplePcreFilterIterator::isAccepted`. fn is_accepted(string: &str, match_regexps: &[String], nomatch_regexps: &[String]) -> bool { for regex in nomatch_regexps { - if preg_match2(regex, string, 0).is_some() { + if preg_match(regex, string).is_some() { return false; } } if !match_regexps.is_empty() { for regex in match_regexps { - if preg_match2(regex, string, 0).is_some() { + if preg_match(regex, string).is_some() { return true; } } @@ -642,7 +642,7 @@ fn is_regex(str: &str) -> bool { let available_modifiers = "imsxuADUn"; let pattern = format!("/^(.{{3,}}?)[{available_modifiers}]*$/"); - if let Some(matches) = preg_match2(&pattern, str, 0) { + if let Some(matches) = preg_match(&pattern, str) { let group = matches.get(1).unwrap_or_default().to_string(); let bytes = group.as_bytes(); let start = bytes @@ -655,7 +655,7 @@ fn is_regex(str: &str) -> bool { .unwrap_or_default(); if start == end { - return preg_match2(php_regex!("/[*?[:alnum:] \\\\]/"), &start, 0).is_none(); + return preg_match(php_regex!("/[*?[:alnum:] \\\\]/"), &start).is_none(); } for (open, close) in [("{", "}"), ("(", ")"), ("[", "]"), ("<", ">")] { @@ -683,7 +683,7 @@ fn comparator_test(operator: &str, test: i64, target: i64) -> bool { /// `DateComparator::__construct`, returning `(operator, target unix timestamp)`. fn parse_date_comparator(test: &str) -> (String, i64) { let pattern = "#^\\s*(==|!=|[<>]=?|after|since|before|until)?\\s*(.+?)\\s*$#i"; - let Some(matches) = preg_match2(pattern, test, 0) else { + let Some(matches) = preg_match(pattern, test) else { panic!("Don't understand \"{test}\" as a date test."); }; diff --git a/crates/shirabe/src/advisory/auditor.rs b/crates/shirabe/src/advisory/auditor.rs index 563da5b3..2ae64659 100644 --- a/crates/shirabe/src/advisory/auditor.rs +++ b/crates/shirabe/src/advisory/auditor.rs @@ -14,7 +14,7 @@ use crate::util::PackageInfo; use indexmap::IndexMap; use shirabe_php_shim::{ DATE_ATOM, InvalidArgumentException, PhpMixed, array_all, array_any, array_key_exists, - array_keys, array_reduce, get_class, preg_match2, + array_keys, array_reduce, get_class, preg_match, }; use shirabe_symfony_console::formatter::OutputFormatter; use shirabe_symfony_console::helper::Cell; @@ -290,7 +290,7 @@ impl Auditor { }; if pkg.is_abandoned() && (filter.is_none() - || preg_match2(filter.as_ref().unwrap(), &pkg.get_name(), 0).is_none()) + || preg_match(filter.as_ref().unwrap(), &pkg.get_name()).is_none()) { result.push(pkg); } diff --git a/crates/shirabe/src/autoload/autoload_generator.rs b/crates/shirabe/src/autoload/autoload_generator.rs index 05115123..d5e1fcba 100644 --- a/crates/shirabe/src/autoload/autoload_generator.rs +++ b/crates/shirabe/src/autoload/autoload_generator.rs @@ -26,7 +26,7 @@ use shirabe_class_map_generator::class_map_generator::ClassMapGenerator; use shirabe_php_shim::{ InvalidArgumentException, PhpMixed, PregMatches, array_keys, array_map, array_merge_map, array_merge_recursive, array_shift, array_slice_strs, array_unique, bin2hex, explode, - file_exists, file_get_contents, hash, implode, is_array, ksort, ltrim, php_regex, preg_match2, + file_exists, file_get_contents, hash, implode, is_array, ksort, ltrim, php_regex, preg_match, preg_quote, preg_replace, preg_replace_callback, random_bytes, realpath, str_replace, strlen, strpos, strtr, substr, substr_count, trim, unlink, var_export, }; @@ -558,11 +558,9 @@ return array( { let content = file_get_contents(format!("{}/autoload.php", vendor_path)).unwrap_or_default(); - if let Some(matches) = preg_match2( - php_regex!("{ComposerAutoloaderInit([^:\\s]+)::}"), - &content, - 0, - ) { + if let Some(matches) = + preg_match(php_regex!("{ComposerAutoloaderInit([^:\\s]+)::}"), &content) + { suffix = matches.get(1).map(str::to_string); } } @@ -1128,7 +1126,7 @@ return array( } } - if preg_match2(php_regex!("{\\.phar([\\\\/]|$)}"), &path, 0).is_some() { + if preg_match(php_regex!("{\\.phar([\\\\/]|$)}"), &path).is_some() { base_dir = format!("'phar://' . {}", base_dir); } @@ -1153,8 +1151,7 @@ return array( let package = &item.0; let links = array_merge_map(package.get_replaces(), package.get_provides()); for (_k, link) in &links { - if let Some(matches) = - preg_match2(php_regex!("{^ext-(.+)$}iD"), link.get_target(), 0) + if let Some(matches) = preg_match(php_regex!("{^ext-(.+)$}iD"), link.get_target()) && let Some(ext) = matches.get(1).map(str::to_string) { extension_providers @@ -1198,7 +1195,7 @@ return array( if check_platform.as_bool() == Some(true) && let Some(matches) = - preg_match2(php_regex!("{^ext-(.+)$}iD"), link.get_target(), 0) + preg_match(php_regex!("{^ext-(.+)$}iD"), link.get_target()) { let ext_key = matches.get(1).unwrap_or_default().to_string(); // skip extension checks if they have a valid provider/replacer diff --git a/crates/shirabe/src/cache.rs b/crates/shirabe/src/cache.rs index 80085ff9..919d0ac2 100644 --- a/crates/shirabe/src/cache.rs +++ b/crates/shirabe/src/cache.rs @@ -9,7 +9,7 @@ use chrono::Utc; use shirabe_php_shim::{ ErrorException, bin2hex, clearstatcache, date_format_to_strftime, dirname, disk_free_space, file_exists, file_get_contents, file_put_contents, filemtime, function_exists, hash_file, - is_dir, is_writable, mkdir, php_regex, preg_match2, preg_replace, random_bytes, random_int, + is_dir, is_writable, mkdir, php_regex, preg_match, preg_replace, random_bytes, random_int, rename, time, unlink, }; use shirabe_symfony_finder::Finder; @@ -94,10 +94,9 @@ impl Cache { } pub fn is_usable(path: &str) -> bool { - preg_match2( + preg_match( php_regex!(r"{(^|[\\\\/])(\$null|nul|NUL|/dev/null)([\\\\/]|$)}"), path, - 0, ) .is_none() } @@ -188,12 +187,11 @@ impl Cache { true, crate::io::DEBUG, ); - if let Some(m) = preg_match2( + if let Some(m) = preg_match( php_regex!( r"{^file_put_contents\(\): Only ([0-9]+) of ([0-9]+) bytes written}" ), e.get_message(), - 0, ) { // Remove partial file. unlink(&temp_file_name); diff --git a/crates/shirabe/src/command/archive_command.rs b/crates/shirabe/src/command/archive_command.rs index f2f26702..e10601ac 100644 --- a/crates/shirabe/src/command/archive_command.rs +++ b/crates/shirabe/src/command/archive_command.rs @@ -26,7 +26,7 @@ use crate::util::Platform; use crate::util::ProcessExecutor; use crate::util::r#loop::Loop; use indexmap::IndexMap; -use shirabe_php_shim::{LogicException, get_debug_type, impl_php_class, php_regex, preg_match2}; +use shirabe_php_shim::{LogicException, get_debug_type, impl_php_class, php_regex, preg_match}; use shirabe_symfony_console::command::Command; use shirabe_symfony_console::input::InputInterface; use shirabe_symfony_console::output::OutputInterface; @@ -228,11 +228,8 @@ impl ArchiveCommand { } if let Some(version_str) = &version - && let Some(matches) = preg_match2( - php_regex!(r"{@(stable|RC|beta|alpha|dev)$}i"), - version_str, - 0, - ) + && let Some(matches) = + preg_match(php_regex!(r"{@(stable|RC|beta|alpha|dev)$}i"), version_str) { let m1 = matches.get(1).unwrap_or_default().to_string(); let m0 = matches.get(0).unwrap_or_default().to_string(); diff --git a/crates/shirabe/src/command/bump_command.rs b/crates/shirabe/src/command/bump_command.rs index db4888c7..3c75c937 100644 --- a/crates/shirabe/src/command/bump_command.rs +++ b/crates/shirabe/src/command/bump_command.rs @@ -18,7 +18,7 @@ use crate::util::Filesystem; use crate::util::Silencer; use shirabe_php_shim::{ PhpMixed, file_get_contents, file_put_contents, impl_php_class, is_writable, php_regex, - preg_match2, preg_replace, strtolower, + preg_match, preg_replace, strtolower, }; use shirabe_symfony_console::command::Command; use shirabe_symfony_console::input::InputInterface; @@ -186,7 +186,7 @@ impl BumpCommand { .collect(); let pattern = base_package::package_names_to_regexp(&unique_lower, "{^(?:%s)$}iD"); for (key, reqs) in tasks.iter_mut() { - reqs.retain(|pkg_name, _| preg_match2(&pattern, pkg_name, 0).is_some()); + reqs.retain(|pkg_name, _| preg_match(&pattern, pkg_name).is_some()); } packages_filter } else { diff --git a/crates/shirabe/src/command/completion_trait.rs b/crates/shirabe/src/command/completion_trait.rs index ce0aef58..eda80164 100644 --- a/crates/shirabe/src/command/completion_trait.rs +++ b/crates/shirabe/src/command/completion_trait.rs @@ -11,7 +11,7 @@ use crate::repository::RepositoryInterfaceHandle; use crate::repository::RootPackageRepository; use crate::repository::repository_interface::{SEARCH_NAME, SEARCH_VENDOR, SearchResult}; use indexmap::IndexMap; -use shirabe_php_shim::{PhpMixed, php_regex, preg_match2, preg_quote}; +use shirabe_php_shim::{PhpMixed, php_regex, preg_match, preg_quote}; /// Adds completion to arguments and options. /// @@ -256,10 +256,9 @@ pub trait CompletionTrait: BaseCommand { /// platform packages from the ones available on the currently-running PHP fn suggest_available_package_incl_platform(&self) -> SuggestedValues { SuggestedValues::Closure(Box::new(|this, input, suggestions| { - let matches = if preg_match2( + let matches = if preg_match( php_regex!(r"{^(ext|lib|php)(-|$)|^com}"), &input.get_completion_value(), - 0, ) .is_some() { @@ -297,7 +296,7 @@ pub trait CompletionTrait: BaseCommand { let mut names: Vec<String> = vec![]; for package in repos.get_packages()? { let name = package.get_name(); - if preg_match2(pattern.clone(), &name, 0).is_some() { + if preg_match(pattern.clone(), &name).is_some() { names.push(name); } } diff --git a/crates/shirabe/src/command/config_command.rs b/crates/shirabe/src/command/config_command.rs index 7bf091a1..f1eb14b0 100644 --- a/crates/shirabe/src/command/config_command.rs +++ b/crates/shirabe/src/command/config_command.rs @@ -22,7 +22,7 @@ use shirabe_php_shim::{ InvalidArgumentException, PhpMixed, RuntimeException, array_is_list, array_merge, escapeshellcmd, exec, explode, file_exists, impl_php_class, implode, in_array_loose, in_array_strict, is_array, is_bool, is_dir, is_numeric, is_object, is_string, json_encode, - php_regex, preg_match2, preg_replace, str_replace, strpos, strtolower, system, touch, + php_regex, preg_match, preg_replace, str_replace, strpos, strtolower, system, touch, var_export, }; use shirabe_semver::VersionParser; @@ -701,10 +701,9 @@ impl Command for ConfigCommand { let mut source = config.borrow_mut().get_source_of_value(&setting_key); let mut value: PhpMixed; - if let Some(matches) = preg_match2( + if let Some(matches) = preg_match( php_regex!("/^repos?(?:itories)?(?:\\.(.+))?/"), &setting_key, - 0, ) { if matches.get(1).is_none() { value = data @@ -925,9 +924,7 @@ impl Command for ConfigCommand { return Ok(0); } // handle preferred-install per-package config - if let Some(matches) = - preg_match2(php_regex!("/^preferred-install\\.(.+)/"), &setting_key, 0) - { + if let Some(matches) = preg_match(php_regex!("/^preferred-install\\.(.+)/"), &setting_key) { if input.borrow().get_option("unset")?.as_bool() == Some(true) { self.config_source .borrow_mut() @@ -960,10 +957,9 @@ impl Command for ConfigCommand { } // handle allow-plugins config setting elements true or false to add/remove - if let Some(matches) = preg_match2( + if let Some(matches) = preg_match( php_regex!("{^allow-plugins\\.([a-zA-Z0-9/*-]+)}"), &setting_key, - 0, ) { if input.borrow().get_option("unset")?.as_bool() == Some(true) { self.config_source @@ -1029,8 +1025,7 @@ impl Command for ConfigCommand { } // handle repositories - if let Some(matches) = - preg_match2(php_regex!("/^repos?(?:itories)?\\.(.+)/"), &setting_key, 0) + if let Some(matches) = preg_match(php_regex!("/^repos?(?:itories)?\\.(.+)/"), &setting_key) { if input.borrow().get_option("unset")?.as_bool() == Some(true) { self.config_source @@ -1099,7 +1094,7 @@ impl Command for ConfigCommand { } // handle extra - if let Some(matches) = preg_match2(php_regex!("/^extra\\.(.+)/"), &setting_key, 0) { + if let Some(matches) = preg_match(php_regex!("/^extra\\.(.+)/"), &setting_key) { if input.borrow().get_option("unset")?.as_bool() == Some(true) { self.config_source .borrow_mut() @@ -1171,7 +1166,7 @@ impl Command for ConfigCommand { } // handle suggest - if let Some(matches) = preg_match2(php_regex!("/^suggest\\.(.+)/"), &setting_key, 0) { + if let Some(matches) = preg_match(php_regex!("/^suggest\\.(.+)/"), &setting_key) { if input.borrow().get_option("unset")?.as_bool() == Some(true) { self.config_source .borrow_mut() @@ -1205,7 +1200,7 @@ impl Command for ConfigCommand { } // handle platform - if let Some(matches) = preg_match2(php_regex!("/^platform\\.(.+)/"), &setting_key, 0) { + if let Some(matches) = preg_match(php_regex!("/^platform\\.(.+)/"), &setting_key) { if input.borrow().get_option("unset")?.as_bool() == Some(true) { self.config_source .borrow_mut() @@ -1322,12 +1317,11 @@ impl Command for ConfigCommand { } // handle auth - if let Some(matches) = preg_match2( + if let Some(matches) = preg_match( php_regex!( "/^(bitbucket-oauth|github-oauth|gitlab-oauth|gitlab-token|http-basic|custom-headers|bearer|forgejo-token)\\.(.+)/" ), &setting_key, - 0, ) { if input.borrow().get_option("unset")?.as_bool() == Some(true) { self.auth_config_source @@ -1455,7 +1449,7 @@ impl Command for ConfigCommand { } // Check if the header is in correct "Name: Value" format - if preg_match2(php_regex!("/^[^:]+:\\s*.+$/"), header, 0).is_none() { + if preg_match(php_regex!("/^[^:]+:\\s*.+$/"), header).is_none() { return Err(RuntimeException::new(format!( "Header \"{}\" is not in \"Header-Name: Header-Value\" format", header @@ -1503,7 +1497,7 @@ impl Command for ConfigCommand { } // handle script - if let Some(matches) = preg_match2(php_regex!("/^scripts\\.(.+)/"), &setting_key, 0) { + if let Some(matches) = preg_match(php_regex!("/^scripts\\.(.+)/"), &setting_key) { if input.borrow().get_option("unset")?.as_bool() == Some(true) { self.config_source .borrow_mut() @@ -1742,10 +1736,9 @@ fn build_unique_config_values() -> IndexMap<String, (ValidatorFn, NormalizerFn)> ( Box::new(|val| { PhpMixed::Bool( - preg_match2( + preg_match( php_regex!("/^\\s*([0-9.]+)\\s*(?:([kmg])(?:i?b)?)?\\s*$/i"), val.as_string().unwrap_or(""), - 0, ) .is_some(), ) diff --git a/crates/shirabe/src/command/create_project_command.rs b/crates/shirabe/src/command/create_project_command.rs index fbdcfabb..b2842d9d 100644 --- a/crates/shirabe/src/command/create_project_command.rs +++ b/crates/shirabe/src/command/create_project_command.rs @@ -41,7 +41,7 @@ use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ InvalidArgumentException, PhpMixed, RuntimeException, UnexpectedValueException, array_pop, chdir, explode_with_limit, file_exists, getcwd, impl_php_class, implode, is_dir, is_file, - mkdir, preg_match2, realpath, rtrim, strtolower, unlink, + mkdir, preg_match, realpath, rtrim, strtolower, unlink, }; use shirabe_symfony_console::command::Command; use shirabe_symfony_console::input::InputInterface; @@ -525,7 +525,7 @@ impl CreateProjectCommand { if package_version.is_none() { stability = Some("stable".to_string()); } else { - let matched = preg_match2( + let matched = preg_match( format!( "{{^[^,\\s]*?@({})$}}i", implode( @@ -537,7 +537,6 @@ impl CreateProjectCommand { ) ), package_version.as_deref().unwrap_or(""), - 0, ); if let Some(matched) = matched { stability = Some(matched.get(1).unwrap_or_default().to_string()); diff --git a/crates/shirabe/src/command/diagnose_command.rs b/crates/shirabe/src/command/diagnose_command.rs index f7f84575..860c058b 100644 --- a/crates/shirabe/src/command/diagnose_command.rs +++ b/crates/shirabe/src/command/diagnose_command.rs @@ -37,7 +37,7 @@ use shirabe_php_shim::PhpClass as _; use shirabe_php_shim::{ AnyThrowable, Catch as _, CmpOp, InvalidArgumentException, PHP_EOL, PhpMixed, RuntimeException, disk_free_space, file_exists, filter_var_boolean, hash, impl_php_class, implode, is_array, - is_string, php_regex, preg_match2, rtrim, str_replace, strpos, strstr, strstr3, strtolower, + is_string, php_regex, preg_match, rtrim, str_replace, strpos, strstr, strstr3, strtolower, trim, version_compare, }; use shirabe_symfony_console::command::Command; @@ -861,10 +861,9 @@ impl DiagnoseCommand { warnings.insert("zlib".to_string(), PhpMixed::Bool(true)); } - if let Some(phpinfo_match) = preg_match2( + if let Some(phpinfo_match) = preg_match( php_regex!("{Configure Command(?: *</td><td class=\"v\">| *=> *)(.*?)(?:</td>|$)}m"), &diagnostics.phpinfo_general, - 0, ) { let configure = phpinfo_match.get(1).unwrap_or_default().to_string(); let configure = configure.as_str(); diff --git a/crates/shirabe/src/command/fund_command.rs b/crates/shirabe/src/command/fund_command.rs index ea077ef5..089f69e8 100644 --- a/crates/shirabe/src/command/fund_command.rs +++ b/crates/shirabe/src/command/fund_command.rs @@ -10,7 +10,7 @@ use crate::package::base_package::{self}; use crate::repository::CompositeRepository; use crate::repository::RepositoryInterface; use indexmap::IndexMap; -use shirabe_php_shim::{PhpMixed, impl_php_class, php_regex, preg_match2}; +use shirabe_php_shim::{PhpMixed, impl_php_class, php_regex, preg_match}; use shirabe_semver::constraint::AnyConstraint; use shirabe_semver::constraint::MatchAllConstraint; use shirabe_symfony_console::command::Command; @@ -63,7 +63,7 @@ impl FundCommand { .unwrap_or(""); if r#type == "github" && let Some(matches) = - preg_match2(php_regex!(r"{^https://github.com/([^/]+)$}"), &url, 0) + preg_match(php_regex!(r"{^https://github.com/([^/]+)$}"), &url) && let Some(sponsor) = matches.get(1).map(str::to_string) { url = format!("https://github.com/sponsors/{}", sponsor); diff --git a/crates/shirabe/src/command/init_command.rs b/crates/shirabe/src/command/init_command.rs index b316e4fe..3ca6c0fb 100644 --- a/crates/shirabe/src/command/init_command.rs +++ b/crates/shirabe/src/command/init_command.rs @@ -24,7 +24,7 @@ use shirabe_php_shim::{ CaptureKey, FILE_IGNORE_NEW_LINES, InvalidArgumentException, PHP_EOL, PHP_SERVER, PhpMixed, array_flip_strings, array_intersect_key, array_map, basename, empty, explode, file, file_exists, file_get_contents, file_put_contents, get_current_user, impl_php_class, implode, - is_dir, is_string, php_regex, preg_match_all, preg_match2, preg_quote, preg_replace, realpath, + is_dir, is_string, php_regex, preg_match, preg_match_all, preg_quote, preg_replace, realpath, str_replace, strpos, strtolower, trim, ucwords, }; use shirabe_spdx_licenses::SpdxLicenses; @@ -89,10 +89,9 @@ impl InitCommand { &self, author: &str, ) -> anyhow::Result<IndexMap<String, Option<String>>> { - if let Some(m) = preg_match2( + if let Some(m) = preg_match( php_regex!(r#"/^(?P<name>[- .,\p{L}\p{N}\p{Mn}\'’\"()]+)(?:\s+<(?P<email>.+?)>)?$/u"#), author, - 0, ) { let email = m.name("email").map(str::to_string); if let Some(ref email) = email @@ -210,7 +209,7 @@ impl InitCommand { let lines = file(ignore_file, FILE_IGNORE_NEW_LINES).unwrap_or_default(); for line in &lines { - if preg_match2(&pattern, line, 0).is_some() { + if preg_match(&pattern, line).is_some() { return true; } } @@ -498,13 +497,12 @@ impl Command for InitCommand { }); if options.contains_key("name") - && preg_match2( + && preg_match( php_regex!(r"{^[a-z0-9]([_.-]?[a-z0-9]+)*\/[a-z0-9](([_.]|-{1,2})?[a-z0-9]+)*$}D"), options .get("name") .and_then(|v| v.as_string()) .unwrap_or(""), - 0, ) .is_none() { @@ -910,11 +908,7 @@ impl Command for InitCommand { return Ok(PhpMixed::String(name_for_validate.clone())); } - if preg_match2( - php_regex!(r"{^[a-z0-9]([_.-]?[a-z0-9]+)*\/[a-z0-9](([_.]|-{1,2})?[a-z0-9]+)*$}D"), - value.as_string().unwrap_or(""), - 0, - ) + if preg_match(php_regex!(r"{^[a-z0-9]([_.-]?[a-z0-9]+)*\/[a-z0-9](([_.]|-{1,2})?[a-z0-9]+)*$}D"), value.as_string().unwrap_or("")) .is_none() { return Err(InvalidArgumentException::new(format!( @@ -1226,7 +1220,7 @@ impl Command for InitCommand { value_str }; - if preg_match2(php_regex!(r"{^[^/][A-Za-z0-9\-_/]+/$}"), &value_or_default, 0) + if preg_match(php_regex!(r"{^[^/][A-Za-z0-9\-_/]+/$}"), &value_or_default) .is_none() { return Err(InvalidArgumentException::new(format!( diff --git a/crates/shirabe/src/command/package_discovery_trait.rs b/crates/shirabe/src/command/package_discovery_trait.rs index a5b606a8..8e25c1b9 100644 --- a/crates/shirabe/src/command/package_discovery_trait.rs +++ b/crates/shirabe/src/command/package_discovery_trait.rs @@ -23,7 +23,7 @@ use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ Exception, InvalidArgumentException, LogicException, PHP_EOL, PhpMixed, array_keys, array_slice, asort, explode, file_get_contents, implode, in_array_strict, is_array, is_file, - is_numeric, json_decode_assoc, levenshtein, php_regex, preg_match2, strlen, strpos, trim, + is_numeric, json_decode_assoc, levenshtein, php_regex, preg_match, strlen, strpos, trim, }; use shirabe_symfony_console::input::InputInterface; use shirabe_symfony_console::output::OutputInterface; @@ -143,10 +143,9 @@ pub trait PackageDiscoveryTrait: BaseCommand { for mut requirement in requires_norm { if requirement.contains_key("version") - && preg_match2( + && preg_match( php_regex!(r"{^\d+(\.\d+)?$}"), requirement.get("version").map(|s| s.as_str()).unwrap_or(""), - 0, ) .is_some() { @@ -331,10 +330,9 @@ pub trait PackageDiscoveryTrait: BaseCommand { } } - if let Some(m) = preg_match2( + if let Some(m) = preg_match( php_regex!(r"{^\s*(?P<name>[\S/]+)(?:\s+(?P<version>\S+))?\s*$}"), &selection, - 0, ) { if let Some(v) = m.name("version").map(str::to_string) { // parsing `acme/example ~2.3` diff --git a/crates/shirabe/src/command/reinstall_command.rs b/crates/shirabe/src/command/reinstall_command.rs index 05c277d5..d0b36778 100644 --- a/crates/shirabe/src/command/reinstall_command.rs +++ b/crates/shirabe/src/command/reinstall_command.rs @@ -15,7 +15,7 @@ use crate::plugin::CommandEvent; use crate::plugin::PluginEvents; use crate::script::ScriptEvents; use crate::util::Platform; -use shirabe_php_shim::{InvalidArgumentException, impl_php_class, preg_match2}; +use shirabe_php_shim::{InvalidArgumentException, impl_php_class, preg_match}; use shirabe_symfony_console::command::Command; use shirabe_symfony_console::input::InputInterface; use shirabe_symfony_console::output::OutputInterface; @@ -136,7 +136,7 @@ impl Command for ReinstallCommand { let pattern_regexp = base_package::package_name_to_regexp(pattern); let mut matched = false; for package in local_repo.get_canonical_packages()? { - if preg_match2(&pattern_regexp, &package.get_name(), 0).is_some() { + if preg_match(&pattern_regexp, &package.get_name()).is_some() { matched = true; package_names_to_reinstall.push(package.get_name()); packages_to_reinstall.push(package); diff --git a/crates/shirabe/src/command/repository_command.rs b/crates/shirabe/src/command/repository_command.rs index bbd1eace..daeaaf74 100644 --- a/crates/shirabe/src/command/repository_command.rs +++ b/crates/shirabe/src/command/repository_command.rs @@ -12,7 +12,7 @@ use crate::json::JsonFile; use indexmap::IndexMap; use shirabe_php_shim::{ InvalidArgumentException, PhpMixed, RuntimeException, impl_php_class, parse_url, php_regex, - preg_match2, strtolower, + preg_match, strtolower, }; use shirabe_symfony_console::command::Command; use shirabe_symfony_console::input::InputInterface; @@ -368,7 +368,7 @@ impl Command for RepositoryCommand { .into()); } let arg1_str = arg1.as_deref().unwrap(); - let repo_config: PhpMixed = if preg_match2(php_regex!(r"{^\s*\{}"), arg1_str, 0) + let repo_config: PhpMixed = if preg_match(php_regex!(r"{^\s*\{}"), arg1_str) .is_some() { JsonFile::parse_json(Some(arg1_str), None)? diff --git a/crates/shirabe/src/command/show_command.rs b/crates/shirabe/src/command/show_command.rs index e8072ca8..acb4f5c8 100644 --- a/crates/shirabe/src/command/show_command.rs +++ b/crates/shirabe/src/command/show_command.rs @@ -39,7 +39,7 @@ use indexmap::IndexMap; use shirabe_php_shim::{ CmpOp, DATE_ATOM, InvalidArgumentException, LogicException, PhpMixed, UnexpectedValueException, array_search, date_format_to_strftime, date_local, extension_loaded, impl_php_class, - in_array_loose, in_array_strict, php_regex, preg_match2, preg_quote, preg_replace, realpath, + in_array_loose, in_array_strict, php_regex, preg_match, preg_quote, preg_replace, realpath, strtolower, version_compare, }; use shirabe_semver::Semver; @@ -1373,10 +1373,9 @@ impl ShowCommand { if target_version.is_none() { if major_only - && let Some(groups) = preg_match2( + && let Some(groups) = preg_match( php_regex!(r"{^(?P<zero_major>(?:0\.)+)?(?P<first_meaningful>\d+)\.}"), &package.get_version(), - 0, ) { let zero_major = groups.name("zero_major").unwrap_or_default().to_string(); @@ -2342,7 +2341,7 @@ impl Command for ShowCommand { } let matches_filter = match &package_filter_regex { None => true, - Some(r) => preg_match2(r, &p.get_name(), 0).is_some(), + Some(r) => preg_match(r, &p.get_name()).is_some(), }; if matches_filter { let matches_list = match &package_list_filter { @@ -2421,7 +2420,7 @@ impl Command for ShowCommand { if show_latest && *show_version { for package_or_name in type_packages.values() { if let PackageOrName::Pkg(package) = package_or_name - && preg_match2(&ignored_packages_regex, &package.get_pretty_name(), 0) + && preg_match(&ignored_packages_regex, &package.get_pretty_name()) .is_none() { let latest = self.find_latest_package( @@ -2493,7 +2492,7 @@ impl Command for ShowCommand { package_is_up_to_date = package_is_up_to_date || (latest_package.is_none() && show_major_only); let package_is_ignored = - preg_match2(&ignored_packages_regex, &package.get_pretty_name(), 0) + preg_match(&ignored_packages_regex, &package.get_pretty_name()) .is_some(); if input.borrow().get_option("outdated")?.as_bool() == Some(true) && (package_is_up_to_date || package_is_ignored) diff --git a/crates/shirabe/src/command/update_command.rs b/crates/shirabe/src/command/update_command.rs index 72d97315..dcfbc371 100644 --- a/crates/shirabe/src/command/update_command.rs +++ b/crates/shirabe/src/command/update_command.rs @@ -29,7 +29,7 @@ use crate::util::HttpDownloader; use indexmap::IndexMap; use shirabe_php_shim::{ InvalidArgumentException, PhpMixed, RuntimeException, array_filter, array_intersect, - array_keys, array_merge_map, array_search_in_vec, impl_php_class, php_regex, preg_match2, + array_keys, array_merge_map, array_search_in_vec, impl_php_class, php_regex, preg_match, preg_replace, strtolower, }; use shirabe_semver::Intervals; @@ -115,7 +115,7 @@ impl UpdateCommand { let mut version_selector = self.create_version_selector(composer)?; for package in &installed_packages { if let Some(filter) = &filter - && preg_match2(filter, &package.get_name(), 0).is_none() + && preg_match(filter, &package.get_name()).is_none() { continue; } @@ -378,7 +378,7 @@ impl Command for UpdateCommand { if !packages.is_empty() { let allowlist_packages_with_requirements: Vec<String> = array_filter(&packages, |pkg: &String| -> bool { - preg_match2(php_regex!(r"{\S+[ =:]\S+}"), pkg, 0).is_some() + preg_match(php_regex!(r"{\S+[ =:]\S+}"), pkg).is_some() }); for (package, constraint) in self.format_requirements(allowlist_packages_with_requirements.clone())? @@ -459,7 +459,7 @@ impl Command for UpdateCommand { continue; } let version = package.get_version(); - let matches = preg_match2(php_regex!(r"{^(\d+\.\d+\.\d+)}"), &version, 0); + let matches = preg_match(php_regex!(r"{^(\d+\.\d+\.\d+)}"), &version); let Some(matches) = matches else { continue; }; diff --git a/crates/shirabe/src/composer.rs b/crates/shirabe/src/composer.rs index 6d3c6e26..1ed7abd0 100644 --- a/crates/shirabe/src/composer.rs +++ b/crates/shirabe/src/composer.rs @@ -11,7 +11,7 @@ use crate::package::{LockerInterface, RootPackageInterfaceHandle}; use crate::plugin::PluginManager; use crate::repository::RepositoryManagerInterface; use crate::util::r#loop::Loop; -use shirabe_php_shim::{php_regex, preg_match2}; +use shirabe_php_shim::{php_regex, preg_match}; /// The Composer version this port tracks. Kept as-is so `Composer::VERSION`, the `composer` /// platform package and the HTTP User-Agent keep reporting a value plugins and servers can @@ -43,7 +43,7 @@ pub fn get_version() -> String { return SOURCE_VERSION.to_string(); } if !BRANCH_ALIAS_VERSION.is_empty() - && preg_match2(php_regex!("{^[a-f0-9]{40}$}"), VERSION, 0).is_some() + && preg_match(php_regex!("{^[a-f0-9]{40}$}"), VERSION).is_some() { return format!("{}+{}", BRANCH_ALIAS_VERSION, VERSION); } diff --git a/crates/shirabe/src/config.rs b/crates/shirabe/src/config.rs index 1a14f67f..7e37a544 100644 --- a/crates/shirabe/src/config.rs +++ b/crates/shirabe/src/config.rs @@ -11,7 +11,7 @@ use indexmap::IndexMap; use shirabe_php_shim::{ E_USER_DEPRECATED, PhpMixed, PregMatches, RuntimeException, array_key_exists, array_merge, array_search_mixed, array_unique, empty, filter_var_url, implode, in_array_loose, - in_array_strict, intval, is_array, is_string, parse_url, php_regex, php_to_string, preg_match2, + in_array_strict, intval, is_array, is_string, parse_url, php_regex, php_to_string, preg_match, preg_replace_callback, rtrim, strtolower, strtoupper, strtr, substr, trigger_error, }; @@ -481,10 +481,9 @@ impl Config { .unwrap_or("") .to_string(); if is_composer - && preg_match2( + && preg_match( php_regex!(r"{^https?://(?:[a-z0-9-.]+\.)?packagist.org(/|$)}"), &repo_url, - 0, ) .is_some() { @@ -648,10 +647,9 @@ impl Config { // numbers with kb/mb/gb support, without env var support "cache-files-maxsize" => { let raw = self.config.get(key).map(php_to_string).unwrap_or_default(); - let Some(matches) = preg_match2( + let Some(matches) = preg_match( php_regex!(r"/^\s*([0-9.]+)\s*(?:([kmg])(?:i?b)?)?\s*$/i"), &raw, - 0, ) else { return Err(RuntimeException::new(format!( "Could not parse the value of '{}': {}", @@ -973,13 +971,7 @@ impl Config { /// /// Since the dirs might not exist yet we can not call realpath or it will fail. fn realpath(&self, path: &str) -> String { - if preg_match2( - php_regex!(r"{^(?:/|[a-z]:|[a-z0-9.]+://|\\\\\\\\)}i"), - path, - 0, - ) - .is_some() - { + if preg_match(php_regex!(r"{^(?:/|[a-z]:|[a-z0-9.]+://|\\\\\\\\)}i"), path).is_some() { return path.to_string(); } @@ -1021,7 +1013,7 @@ impl Config { repo_options: &IndexMap<String, PhpMixed>, ) -> anyhow::Result<()> { // Return right away if the URL is malformed or custom (see issue #5173), but only for non-HTTP(S) URLs - if !filter_var_url(url) && preg_match2(php_regex!(r"{^https?://}"), url, 0).is_none() { + if !filter_var_url(url) && preg_match(php_regex!(r"{^https?://}"), url).is_none() { return Ok(()); } diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs index 25379a27..54df0b05 100644 --- a/crates/shirabe/src/console/application.rs +++ b/crates/shirabe/src/console/application.rs @@ -61,7 +61,7 @@ use shirabe_php_shim::{ dirname, disk_free_space, extension_loaded, file_exists, file_get_contents, file_put_contents, function_exists, getcwd, getmypid, glob, ini_set, is_array, is_dir, is_file, is_string, json_decode_assoc, memory_get_peak_usage, memory_get_usage, microtime, php_regex, php_uname, - posix_getuid, preg_grep, preg_match2, preg_quote, preg_split, random_bytes, realpath, + posix_getuid, preg_grep, preg_match, preg_quote, preg_split, random_bytes, realpath, restore_error_handler, round, str_replace, strpos, strtoupper, sys_get_temp_dir, time, unlink, }; use shirabe_seld_json_lint::ParsingException; @@ -1789,11 +1789,10 @@ impl Application { let mut lines: Vec<String> = Vec::new(); let mut line = String::new(); - let mut offset = 0i64; - while let Some(m) = preg_match2(php_regex!(r"/.{1,10000}/u"), &utf8_string, offset as usize) - { + let mut offset = 0usize; + while let Some(m) = preg_match(php_regex!(r"/.{1,10000}/u"), &utf8_string[offset..]) { let m0 = m.get(0).unwrap_or(""); - offset += shirabe_php_shim::strlen(m0); + offset += shirabe_php_shim::strlen(m0) as usize; let chunk = m0; for char in chunk diff --git a/crates/shirabe/src/dependency_resolver/lock_transaction.rs b/crates/shirabe/src/dependency_resolver/lock_transaction.rs index df9a737d..71609658 100644 --- a/crates/shirabe/src/dependency_resolver/lock_transaction.rs +++ b/crates/shirabe/src/dependency_resolver/lock_transaction.rs @@ -5,7 +5,7 @@ use crate::dependency_resolver::Pool; use crate::dependency_resolver::Transaction; use crate::package::PackageInterfaceHandle; use indexmap::IndexMap; -use shirabe_php_shim::{PregMatches, php_regex, preg_match2, preg_replace_callback}; +use shirabe_php_shim::{PregMatches, php_regex, preg_match, preg_replace_callback}; #[derive(Debug)] pub struct LockTransaction { @@ -158,9 +158,9 @@ impl LockTransaction { if package.get_dist_url().is_some() && present_package.get_dist_reference().is_some() - && preg_match2(php_regex!( + && preg_match(php_regex!( r"{^https?://(?:(?:www\.)?bitbucket\.org|(api\.)?github\.com|(?:www\.)?gitlab\.com)/}i" - ), &package.get_dist_url().unwrap(), 0).is_some() + ), &package.get_dist_url().unwrap()).is_some() { // Regex pattern compatibility: // The `regex` crate has no look-around, so `(?<=/|sha=)[a-f0-9]{40}(?=/|$)` is diff --git a/crates/shirabe/src/dependency_resolver/pool_builder.rs b/crates/shirabe/src/dependency_resolver/pool_builder.rs index 8c5064c5..354a794c 100644 --- a/crates/shirabe/src/dependency_resolver/pool_builder.rs +++ b/crates/shirabe/src/dependency_resolver/pool_builder.rs @@ -21,7 +21,7 @@ use crate::repository::RootPackageRepository; use indexmap::IndexMap; use shirabe_php_shim::{ CmpOp, LogicException, PhpMixed, array_flip_strings, array_map, in_array_strict, microtime, - number_format, preg_match2, round, strpos, + number_format, preg_match, round, strpos, }; use shirabe_semver::CompilingMatcher; use shirabe_semver::Intervals; @@ -785,7 +785,7 @@ impl PoolBuilder { fn is_update_allowed(&self, package: PackageInterfaceHandle) -> bool { for pattern in &self.update_allow_list { let pattern_regexp = base_package::package_name_to_regexp(pattern); - if preg_match2(&pattern_regexp, &package.get_name(), 0).is_some() { + if preg_match(&pattern_regexp, &package.get_name()).is_some() { return true; } } @@ -812,13 +812,13 @@ impl PoolBuilder { .borrow_mut() .get_packages()? { - if preg_match2(&pattern_regexp, &package.get_name(), 0).is_some() { + if preg_match(&pattern_regexp, &package.get_name()).is_some() { continue 'outer; } } // update pattern matches a root require? => all good, probably a new package for (package_name, _constraint) in request.get_requires() { - if preg_match2(&pattern_regexp, package_name, 0).is_some() { + if preg_match(&pattern_regexp, package_name).is_some() { if PlatformRepository::is_platform_package(package_name) { matched_platform_package = true; continue; diff --git a/crates/shirabe/src/dependency_resolver/problem.rs b/crates/shirabe/src/dependency_resolver/problem.rs index 867dc3fe..6c1ae8c0 100644 --- a/crates/shirabe/src/dependency_resolver/problem.rs +++ b/crates/shirabe/src/dependency_resolver/problem.rs @@ -12,7 +12,7 @@ use crate::repository::RepositorySet; use indexmap::IndexMap; use shirabe_php_shim::{ CmpOp, LogicException, PhpMixed, extension_loaded, implode, loosely_compare, php_regex, - preg_match2, preg_replace, spl_object_hash, sprintf, str_replace, stripos, strpos, strtolower, + preg_match, preg_replace, spl_object_hash, sprintf, str_replace, stripos, strpos, strtolower, substr, substr_count, version_compare, }; use shirabe_semver::constraint::AnyConstraint; @@ -223,12 +223,11 @@ impl Problem { rule_ref.get_reason(), rule::RULE_PACKAGE_REQUIRES | rule::RULE_PACKAGE_CONFLICT ) { - preg_match2( + preg_match( php_regex!( r"{^(?P<package>\S+) (?P<version>\S+) (?P<type>requires|conflicts)}" ), &message, - 0, ) } else { None @@ -557,7 +556,7 @@ impl Problem { if let Some(c) = constraint && c.is_constraint() && c.get_operator() == Some(CmpOp::Eq) - && preg_match2(php_regex!(r"{^dev-.*#.*}"), &c.get_pretty_string(), 0).is_some() + && preg_match(php_regex!(r"{^dev-.*#.*}"), &c.get_pretty_string()).is_some() { let new_constraint = preg_replace( php_regex!(r"{ +as +([^,\s|]+)$}"), @@ -991,7 +990,7 @@ impl Problem { )); } - if preg_match2(php_regex!(r"{^[A-Za-z0-9_./-]+$}"), package_name, 0).is_none() { + if preg_match(php_regex!(r"{^[A-Za-z0-9_./-]+$}"), package_name).is_none() { let illegal_chars = preg_replace(php_regex!(r"{[A-Za-z0-9_./-]+}"), "", package_name); return Ok(( @@ -1381,7 +1380,7 @@ impl Problem { && c.get_operator() == Some(CmpOp::Eq) && !c.get_version().starts_with("dev-") { - if preg_match2(php_regex!(r"{^\d+(?:\.\d+)*$}"), &c.get_pretty_string(), 0).is_none() { + if preg_match(php_regex!(r"{^\d+(?:\.\d+)*$}"), &c.get_pretty_string()).is_none() { return format!(" {} (exact version match)", c.get_pretty_string()); } diff --git a/crates/shirabe/src/downloader/download_manager.rs b/crates/shirabe/src/downloader/download_manager.rs index f2360f9d..85e05bea 100644 --- a/crates/shirabe/src/downloader/download_manager.rs +++ b/crates/shirabe/src/downloader/download_manager.rs @@ -11,7 +11,7 @@ use indexmap::IndexMap; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ InvalidArgumentException, LogicException, PhpMixed, RuntimeException, array_keys, - array_reverse, array_shift, dirname, implode, in_array_strict, preg_match2, preg_quote, rtrim, + array_reverse, array_shift, dirname, implode, in_array_strict, preg_match, preg_quote, rtrim, str_replace, strtolower, usort, }; @@ -430,7 +430,7 @@ impl DownloadManager { "{{^{}$}}i", str_replace("\\*", ".*", &preg_quote(pattern, None)), ); - if preg_match2(&pattern_regex, &package.get_name(), 0).is_some() { + if preg_match(&pattern_regex, &package.get_name()).is_some() { if "dist" == preference || (!package.is_dev() && "auto" == preference) { return "dist".to_string(); } diff --git a/crates/shirabe/src/downloader/fossil_downloader.rs b/crates/shirabe/src/downloader/fossil_downloader.rs index e7b3a20d..40d5153f 100644 --- a/crates/shirabe/src/downloader/fossil_downloader.rs +++ b/crates/shirabe/src/downloader/fossil_downloader.rs @@ -13,7 +13,7 @@ use crate::util::Filesystem; use crate::util::ProcessExecutor; use indexmap::IndexMap; use shirabe_php_shim::{ - PhpMixed, RuntimeException, impl_php_class, php_regex, preg_match2, preg_split, + PhpMixed, RuntimeException, impl_php_class, php_regex, preg_match, preg_split, }; #[derive(Debug)] @@ -228,7 +228,7 @@ impl VcsDownloader for FossilDownloader { }; for line in lines { - if preg_match2(&match_pattern, &line, 0).is_some() { + if preg_match(&match_pattern, &line).is_some() { break; } log.push_str(&line); diff --git a/crates/shirabe/src/downloader/git_downloader.rs b/crates/shirabe/src/downloader/git_downloader.rs index 6e79576d..be3205b5 100644 --- a/crates/shirabe/src/downloader/git_downloader.rs +++ b/crates/shirabe/src/downloader/git_downloader.rs @@ -19,7 +19,7 @@ use crate::util::Url; use indexmap::IndexMap; use shirabe_php_shim::{ CaptureKey, CmpOp, PhpMixed, RuntimeException, array_map, basename, dirname, impl_php_class, - implode, in_array_strict, is_dir, php_regex, preg_match_all, preg_match2, preg_quote, + implode, in_array_strict, is_dir, php_regex, preg_match, preg_match_all, preg_quote, preg_replace, preg_split, realpath, rtrim, strlen, strpos, substr, trim, version_compare, }; @@ -94,7 +94,7 @@ impl GitDownloader { } let mut refs = trim(&output, None); - let Some(head_match) = preg_match2(php_regex!(r"{^([a-f0-9]+) HEAD$}mi"), &refs, 0) else { + let Some(head_match) = preg_match(php_regex!(r"{^([a-f0-9]+) HEAD$}mi"), &refs) else { // could not match the HEAD for some reason return Ok(None); }; @@ -298,12 +298,11 @@ impl GitDownloader { // check whether non-commitish are branches or tags, and fetch branches with the remote name let git_ref = reference.to_string(); - if preg_match2(php_regex!(r"{^[a-f0-9]{40}$}"), reference, 0).is_none() + if preg_match(php_regex!(r"{^[a-f0-9]{40}$}"), reference).is_none() && branches.is_some() - && preg_match2( + && preg_match( format!("{{^\\s+composer/{}$}}m", preg_quote(reference, None)), branches.as_deref().unwrap_or(""), - 0, ) .is_some() { @@ -346,19 +345,17 @@ impl GitDownloader { } // try to checkout branch by name and then reset it so it's on the proper branch name - if preg_match2(php_regex!(r"{^[a-f0-9]{40}$}"), reference, 0).is_some() { + if preg_match(php_regex!(r"{^[a-f0-9]{40}$}"), reference).is_some() { // add 'v' in front of the branch if it was stripped when generating the pretty name if branches.is_some() - && preg_match2( + && preg_match( format!("{{^\\s+composer/{}$}}m", preg_quote(&branch, None)), branches.as_deref().unwrap_or(""), - 0, ) .is_none() - && preg_match2( + && preg_match( format!("{{^\\s+composer/v{}$}}m", preg_quote(&branch, None)), branches.as_deref().unwrap_or(""), - 0, ) .is_some() { @@ -505,13 +502,12 @@ impl GitDownloader { fn set_push_url(&self, path: &str, url: &str) { // set push url for github projects - if let Some(match_) = preg_match2( + if let Some(match_) = preg_match( format!( "{{^(?:https?|git)://{}/([^/]+)/([^/]+?)(?:\\.git)?$}}", GitUtil::get_github_domains_regex(&self.inner.config.borrow()) ), url, - 0, ) { let protocols = self.inner.config.borrow_mut().get("github-protocols"); let m1 = match_.get(1).unwrap_or_default().to_string(); @@ -647,7 +643,7 @@ impl GitDownloader { fn get_short_hash(&self, reference: &str) -> String { if !self.inner.io.is_verbose() - && preg_match2(php_regex!(r"{^[0-9a-f]{40}$}"), reference, 0).is_some() + && preg_match(php_regex!(r"{^[0-9a-f]{40}$}"), reference).is_some() { return substr(reference, 0, Some(10)); } @@ -1101,9 +1097,9 @@ impl VcsDownloader for GitDownloader { Some(&path), ) == 0 && let Some(origin_match) = - preg_match2(php_regex!(r"{^origin\s+(?P<url>\S+)}m"), &output, 0) + preg_match(php_regex!(r"{^origin\s+(?P<url>\S+)}m"), &output) && let Some(composer_match) = - preg_match2(php_regex!(r"{^composer\s+(?P<url>\S+)}m"), &output, 0) + preg_match(php_regex!(r"{^composer\s+(?P<url>\S+)}m"), &output) { let origin_url = origin_match.name("url").unwrap_or_default().to_string(); let composer_url = composer_match.name("url").unwrap_or_default().to_string(); diff --git a/crates/shirabe/src/downloader/svn_downloader.rs b/crates/shirabe/src/downloader/svn_downloader.rs index a31e89c9..42152eb3 100644 --- a/crates/shirabe/src/downloader/svn_downloader.rs +++ b/crates/shirabe/src/downloader/svn_downloader.rs @@ -16,8 +16,8 @@ use crate::util::ProcessExecutor; use crate::util::Svn as SvnUtil; use indexmap::IndexMap; use shirabe_php_shim::{ - CmpOp, PhpMixed, RuntimeException, impl_php_class, is_dir, php_regex, preg_match2, - preg_replace, preg_split, version_compare, + CmpOp, PhpMixed, RuntimeException, impl_php_class, is_dir, php_regex, preg_match, preg_replace, + preg_split, version_compare, }; #[derive(Debug)] @@ -353,8 +353,8 @@ impl VcsDownloader for SvnDownloader { to_reference: &str, path: &str, ) -> anyhow::Result<String> { - if preg_match2(php_regex!(r"{@(\d+)$}"), from_reference, 0).is_some() - && preg_match2(php_regex!(r"{@(\d+)$}"), to_reference, 0).is_some() + if preg_match(php_regex!(r"{@(\d+)$}"), from_reference).is_some() + && preg_match(php_regex!(r"{@(\d+)$}"), to_reference).is_some() { // retrieve the svn base url from the checkout folder let command = vec![ @@ -382,7 +382,7 @@ impl VcsDownloader for SvnDownloader { } let url_pattern = "#<url>(.*)</url>#"; - let base_url = if let Some(matches) = preg_match2(url_pattern, &output, 0) { + let base_url = if let Some(matches) = preg_match(url_pattern, &output) { matches.get(1).unwrap_or_default().to_string() } else { return Err(RuntimeException::new(format!( @@ -453,7 +453,7 @@ impl ChangeReportInterface for SvnDownloader { ); Ok( - if preg_match2(php_regex!("{^ *[^X ] +}m"), &output, 0).is_some() { + if preg_match(php_regex!("{^ *[^X ] +}m"), &output).is_some() { Some(output) } else { None diff --git a/crates/shirabe/src/downloader/zip_downloader.rs b/crates/shirabe/src/downloader/zip_downloader.rs index 7b0ad050..565005d9 100644 --- a/crates/shirabe/src/downloader/zip_downloader.rs +++ b/crates/shirabe/src/downloader/zip_downloader.rs @@ -12,7 +12,7 @@ use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ CmpOp, ErrorException, PhpMixed, RuntimeException, UnexpectedValueException, ZipArchive, bin2hex, class_exists, file_exists, file_get_contents, filesize, function_exists, hash_file, - impl_php_class, is_file, json_encode, php_regex, preg_match2, random_int, str_replace, strlen, + impl_php_class, is_file, json_encode, php_regex, preg_match, random_int, str_replace, strlen, substr, version_compare, }; use shirabe_symfony_process::ExecutableFinder; @@ -112,11 +112,8 @@ impl ZipDownloader { .execute(&[command_spec[1].as_str()], &mut output, None::<&str>) .unwrap_or(1) == 0 - && let Some(m) = preg_match2( - php_regex!(r"{^\s*7-Zip(?:\s\[64\])?\s([0-9.]+)}"), - &output, - 0, - ) + && let Some(m) = + preg_match(php_regex!(r"{^\s*7-Zip(?:\s\[64\])?\s([0-9.]+)}"), &output) { let m1 = m.get(1).unwrap_or_default().to_string(); if version_compare(&m1, "21.01", CmpOp::Lt) { diff --git a/crates/shirabe/src/event_dispatcher/event_dispatcher.rs b/crates/shirabe/src/event_dispatcher/event_dispatcher.rs index 06ce21cc..9cb38599 100644 --- a/crates/shirabe/src/event_dispatcher/event_dispatcher.rs +++ b/crates/shirabe/src/event_dispatcher/event_dispatcher.rs @@ -29,7 +29,7 @@ use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ InvalidArgumentException, PhpMixed, RuntimeException, array_pop, array_push, array_search_in_vec, array_splice, file_exists, get_class, hash, implode, ini_get, is_array, - is_callable, is_object, is_string, krsort, php_regex, preg_match2, preg_quote, preg_replace, + is_callable, is_object, is_string, krsort, php_regex, preg_match, preg_quote, preg_replace, preg_replace_callback, realpath, spl_autoload_functions, spl_autoload_register, spl_autoload_unregister, spl_object_hash, str_replace, strlen, strpos, strtoupper, substr, trim, @@ -922,10 +922,9 @@ try {{ .get_binaries(); if !possible_local_binaries.is_empty() { for local_exec in &possible_local_binaries { - if preg_match2( + if preg_match( format!("{{\\b{}$}}", preg_quote(&callable_str, None)), local_exec, - 0, ) .is_some() { @@ -967,7 +966,7 @@ try {{ // match somename (not in quote, and not a qualified path) and if it is not a valid path from CWD then try to find it // in $PATH. This allows support for `@php foo` where foo is a binary name found in PATH but not an actual relative path if let Some(m) = - preg_match2(php_regex!("{^[^\\'\"\\s/\\\\]+}"), &path_and_args, 0) + preg_match(php_regex!("{^[^\\'\"\\s/\\\\]+}"), &path_and_args) { let m0 = m.get(0).unwrap_or_default().to_string(); if !file_exists(&m0) { diff --git a/crates/shirabe/src/filter/platform_requirement_filter/ignore_list_platform_requirement_filter.rs b/crates/shirabe/src/filter/platform_requirement_filter/ignore_list_platform_requirement_filter.rs index 5fcdc629..de71a6ab 100644 --- a/crates/shirabe/src/filter/platform_requirement_filter/ignore_list_platform_requirement_filter.rs +++ b/crates/shirabe/src/filter/platform_requirement_filter/ignore_list_platform_requirement_filter.rs @@ -3,7 +3,7 @@ use crate::filter::platform_requirement_filter::PlatformRequirementFilterInterface; use crate::package::base_package::{self}; use crate::repository::PlatformRepository; -use shirabe_php_shim::preg_match2; +use shirabe_php_shim::preg_match; use shirabe_semver::Interval; use shirabe_semver::Intervals; use shirabe_semver::constraint::AnyConstraint; @@ -47,13 +47,12 @@ impl IgnoreListPlatformRequirementFilter { return Ok(constraint); } - if !allow_upper_bound_override - || preg_match2(&self.ignore_upper_bound_regex, req, 0).is_none() + if !allow_upper_bound_override || preg_match(&self.ignore_upper_bound_regex, req).is_none() { return Ok(constraint); } - if preg_match2(&self.ignore_regex, req, 0).is_some() { + if preg_match(&self.ignore_regex, req).is_some() { return Ok(MatchAllConstraint::new(None).into()); } @@ -87,14 +86,14 @@ impl PlatformRequirementFilterInterface for IgnoreListPlatformRequirementFilter if !PlatformRepository::is_platform_package(req) { return false; } - preg_match2(&self.ignore_regex, req, 0).is_some() + preg_match(&self.ignore_regex, req).is_some() } fn is_upper_bound_ignored(&self, req: &str) -> bool { if !PlatformRepository::is_platform_package(req) { return false; } - self.is_ignored(req) || preg_match2(&self.ignore_upper_bound_regex, req, 0).is_some() + self.is_ignored(req) || preg_match(&self.ignore_upper_bound_regex, req).is_some() } fn as_any(&self) -> &dyn std::any::Any { diff --git a/crates/shirabe/src/installer/binary_installer.rs b/crates/shirabe/src/installer/binary_installer.rs index 4e3b5e4c..554620df 100644 --- a/crates/shirabe/src/installer/binary_installer.rs +++ b/crates/shirabe/src/installer/binary_installer.rs @@ -10,7 +10,7 @@ use crate::util::ProcessExecutor; use crate::util::Silencer; use shirabe_php_shim::{ PhpMixed, basename, basename_with_suffix, chmod, dirname, fclose, fgets, file_exists, - file_get_contents5, file_put_contents, fopen, is_dir, is_file, is_link, php_regex, preg_match2, + file_get_contents5, file_put_contents, fopen, is_dir, is_file, is_link, php_regex, preg_match, realpath, rmdir, substr, trim, umask, }; @@ -200,10 +200,9 @@ impl BinaryInstaller { } Err(_) => String::new(), }; - if let Some(m) = preg_match2( + if let Some(m) = preg_match( php_regex!(r"{^#!/(?:usr/bin/env )?(?:[^/]+/)*(.+)$}m"), &line, - 0, ) { return trim(m.get(1).unwrap_or(""), None); } @@ -316,10 +315,9 @@ impl BinaryInstaller { file_get_contents5(bin, false, PhpMixed::Null, 0, Some(500)).unwrap_or_default(); // For php files, we generate a PHP proxy instead of a shell one, // which allows calling the proxy with a custom php process - if let Some(m) = preg_match2( + if let Some(m) = preg_match( php_regex!(r"{^(#!.*\r?\n)?[\r\n\t ]*<\?php}"), &bin_contents, - 0, ) { // carry over the existing shebang if present, otherwise add our own let proxy_code = match m.get(1) { diff --git a/crates/shirabe/src/io/base_io.rs b/crates/shirabe/src/io/base_io.rs index 08a9fd7e..f6f75267 100644 --- a/crates/shirabe/src/io/base_io.rs +++ b/crates/shirabe/src/io/base_io.rs @@ -8,7 +8,7 @@ use crate::util::Silencer; use indexmap::IndexMap; use shirabe_php_shim::{ JSON_INVALID_UTF8_IGNORE, JSON_UNESCAPED_SLASHES, JSON_UNESCAPED_UNICODE, PhpMixed, - UnexpectedValueException, array_merge, in_array_strict, json_encode_ex, php_regex, preg_match2, + UnexpectedValueException, array_merge, in_array_strict, json_encode_ex, php_regex, preg_match, }; /// ref: composer/vendor/psr/log/Psr/Log/LogLevel.php @@ -156,7 +156,7 @@ pub trait BaseIO: IOInterface { config.merge(&config_outer, "implicit-due-to-auth"); } - if preg_match2(php_regex!(r"{^[.A-Za-z0-9_]+$}"), &token_str, 0).is_none() { + if preg_match(php_regex!(r"{^[.A-Za-z0-9_]+$}"), &token_str).is_none() { return Err(UnexpectedValueException::new(format!( "Your github oauth token for {} contains invalid characters: \"{}\"", domain, token_str diff --git a/crates/shirabe/src/json/json_file.rs b/crates/shirabe/src/json/json_file.rs index 3bfff4d3..8d992449 100644 --- a/crates/shirabe/src/json/json_file.rs +++ b/crates/shirabe/src/json/json_file.rs @@ -13,7 +13,7 @@ use shirabe_php_shim::{ InvalidArgumentException, JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, JSON_UNESCAPED_UNICODE, PhpMixed, PregMatches, RuntimeException, UnexpectedValueException, dirname, file_exists, file_get_contents, file_put_contents, is_dir, is_file, json_decode_assoc, json_decode_obj, - json_encode_ex, mkdir, php_regex, preg_match2, preg_replace_callback, preg_replace2, realpath, + json_encode_ex, mkdir, php_regex, preg_match, preg_replace_callback, preg_replace2, realpath, str_repeat, strlen, strpos, usleep, }; use shirabe_seld_json_lint::{ParsingException, ParsingExceptionDetails}; @@ -107,9 +107,7 @@ impl JsonFile { http_downloader: Option<std::rc::Rc<std::cell::RefCell<HttpDownloader>>>, io: Option<std::rc::Rc<std::cell::RefCell<dyn IOInterface>>>, ) -> anyhow::Result<Self> { - if http_downloader.is_none() - && preg_match2(php_regex!(r"{^https?://}i"), &path, 0).is_some() - { + if http_downloader.is_none() && preg_match(php_regex!(r"{^https?://}i"), &path).is_some() { return Err(InvalidArgumentException::new( "http urls require a HttpDownloader instance to be passed".to_string(), ) @@ -554,7 +552,7 @@ impl JsonFile { } pub fn detect_indenting(json: Option<&str>) -> String { - if let Some(m) = preg_match2(php_regex!(r##"#^([ \t]+)"#m"##), json.unwrap_or(""), 0) { + if let Some(m) = preg_match(php_regex!(r##"#^([ \t]+)"#m"##), json.unwrap_or("")) { return m.get(1).unwrap_or_default().to_string(); } diff --git a/crates/shirabe/src/json/json_manipulator.rs b/crates/shirabe/src/json/json_manipulator.rs index f0cb8790..e224e68e 100644 --- a/crates/shirabe/src/json/json_manipulator.rs +++ b/crates/shirabe/src/json/json_manipulator.rs @@ -7,7 +7,7 @@ use indexmap::IndexMap; use shirabe_php_shim::{ InvalidArgumentException, LogicException, PhpMixed, addcslashes, array_key_exists, array_keys, array_reverse, empty, explode, implode, in_array_loose, is_array, is_int, is_numeric, - json_decode_assoc, json_decode_obj, php_regex, php_truthy, preg_match2, preg_quote, + json_decode_assoc, json_decode_obj, php_regex, php_truthy, preg_match, preg_quote, preg_replace, preg_replace2, rtrim, str_repeat, str_replace, strlen, strnatcmp, strpos, substr, trim, uksort, }; @@ -35,7 +35,7 @@ impl JsonManipulator { if contents.is_empty() { contents = "{}".to_string(); } - if preg_match2(php_regex!("#^\\{(.*)\\}$#s"), &contents, 0).is_none() { + if preg_match(php_regex!("#^\\{(.*)\\}$#s"), &contents).is_none() { return Err(InvalidArgumentException::new( "The json file must be an object ({})".to_string(), ) @@ -112,11 +112,9 @@ impl JsonManipulator { &links[value_end..] ); } else { - if let Some(groups) = preg_match2( - php_regex!("#^\\s*\\{\\s*\\S+.*?(\\s*\\}\\s*)$#s"), - &links, - 0, - ) { + if let Some(groups) = + preg_match(php_regex!("#^\\s*\\{\\s*\\S+.*?(\\s*\\}\\s*)$#s"), &links) + { let groups_1 = groups.get(1).unwrap_or_default().to_string(); // link missing but non empty links links = preg_replace( @@ -735,12 +733,11 @@ impl JsonManipulator { &children[cm.value_end..] ); } else { - if let Some(leading_match) = preg_match2( + if let Some(leading_match) = preg_match( php_regex!( "#^\\{(?P<leadingspace>\\s*?)(?P<content>\\S+.*?)?(?P<trailingspace>\\s*)\\}$#s" ), &children, - 0, ) { let mut whitespace = leading_match .name("trailingspace") @@ -893,7 +890,7 @@ impl JsonManipulator { // try and find a match for the subkey let key_regex = str_replace("/", "\\\\?/", &preg_quote(&name_owned, None)); let mut children_clean: Option<String> = None; - if preg_match2(format!("{{\"{}\"\\s*:}}i", key_regex), &children, 0).is_some() { + if preg_match(format!("{{\"{}\"\\s*:}}i", key_regex), &children).is_some() { // find best match for the value of "name". The PHP pattern `"name"\s*:\s*(?&json)` is // not anchored, so it can match the key at several nesting levels; collect every such // occurrence and keep the longest, reproducing PHP's behaviour. @@ -936,10 +933,9 @@ impl JsonManipulator { let children_clean = children_clean.ok_or_else(|| InvalidArgumentException::new("JsonManipulator: $childrenClean is not defined. Please report at https://github.com/nsfisis/php-shirabe/issues/new.".to_string()))?; // no child data left, $name was the only key in - if let Some(empty_match) = preg_match2( + if let Some(empty_match) = preg_match( php_regex!("#^\\{\\s*?(?P<content>\\S+.*?)?(?P<trailingspace>\\s*)\\}$#s"), &children_clean, - 0, ) && empty_match.name("content").is_none() { self.contents = format!( @@ -1032,12 +1028,11 @@ impl JsonManipulator { return Ok(false); } - if let Some(leading_match) = preg_match2( + if let Some(leading_match) = preg_match( php_regex!( "#^\\[(?P<leadingspace>\\s*?)(?P<content>\\S+.*?)?(?P<trailingspace>\\s*)\\]$#s" ), &children, - 0, ) { let leading_whitespace = leading_match .name("leadingspace") @@ -1322,8 +1317,7 @@ impl JsonManipulator { } // append at the end of the file and keep whitespace - if let Some(tail_match) = preg_match2(php_regex!("#[^{\\s](\\s*)\\}$#"), &self.contents, 0) - { + if let Some(tail_match) = preg_match(php_regex!("#[^{\\s](\\s*)\\}$#"), &self.contents) { let tail_match_1 = tail_match.get(1).unwrap_or_default().to_string(); self.contents = preg_replace( format!("#{}\\}}$#", tail_match_1), @@ -1396,8 +1390,8 @@ impl JsonManipulator { // check that we are not leaving a dangling comma on the previous line if the last line was removed let mut start = self.contents[..m.key_pos].to_string(); let end = self.contents[e..].to_string(); - if preg_match2(php_regex!("#,\\s*$#"), &start, 0).is_some() - && preg_match2(php_regex!("#^\\}$#"), &end, 0).is_some() + if preg_match(php_regex!("#,\\s*$#"), &start).is_some() + && preg_match(php_regex!("#^\\}$#"), &end).is_some() { start = rtrim( &preg_replace(php_regex!("#,(\\s*)$#"), "$1", &start), @@ -1406,7 +1400,7 @@ impl JsonManipulator { } self.contents = format!("{}{}", start, end); - if preg_match2(php_regex!("#^\\{\\s*\\}\\s*$#"), &self.contents, 0).is_some() { + if preg_match(php_regex!("#^\\{\\s*\\}\\s*$#"), &self.contents).is_some() { self.contents = "{\n}".to_string(); } diff --git a/crates/shirabe/src/package/archiver/archive_manager.rs b/crates/shirabe/src/package/archiver/archive_manager.rs index 4f9e2ddc..83d5cc94 100644 --- a/crates/shirabe/src/package/archiver/archive_manager.rs +++ b/crates/shirabe/src/package/archiver/archive_manager.rs @@ -11,7 +11,7 @@ use crate::util::SyncHelper; use crate::util::r#loop::Loop; use indexmap::IndexMap; use shirabe_php_shim::{ - InvalidArgumentException, RuntimeException, bin2hex, file_exists, php_regex, preg_match2, + InvalidArgumentException, RuntimeException, bin2hex, file_exists, php_regex, preg_match, preg_replace, random_bytes, realpath, sys_get_temp_dir, }; @@ -65,7 +65,7 @@ impl ArchiveManager { let dist_reference = package.get_dist_reference(); if let Some(ref dist_ref) = dist_reference { - if preg_match2(php_regex!("{^[a-f0-9]{40}$}"), dist_ref, 0).is_some() { + if preg_match(php_regex!("{^[a-f0-9]{40}$}"), dist_ref).is_some() { parts.insert("dist_reference".to_string(), dist_ref.to_string()); if let Some(dist_type) = package.get_dist_type() { parts.insert("dist_type".to_string(), dist_type); diff --git a/crates/shirabe/src/package/archiver/base_exclude_filter.rs b/crates/shirabe/src/package/archiver/base_exclude_filter.rs index 16a189a8..8186e95c 100644 --- a/crates/shirabe/src/package/archiver/base_exclude_filter.rs +++ b/crates/shirabe/src/package/archiver/base_exclude_filter.rs @@ -1,6 +1,6 @@ //! ref: composer/src/Composer/Package/Archiver/BaseExcludeFilter.php -use shirabe_php_shim::preg_match2; +use shirabe_php_shim::preg_match; use shirabe_symfony_finder::Glob; #[derive(Debug)] @@ -86,7 +86,7 @@ pub trait BaseExcludeFilter { relative_path }; - if preg_match2(pattern, path, 0).is_some() { + if preg_match(pattern, path).is_some() { exclude = !negate; } } diff --git a/crates/shirabe/src/package/loader/array_loader.rs b/crates/shirabe/src/package/loader/array_loader.rs index b6b5ac1e..00f9026e 100644 --- a/crates/shirabe/src/package/loader/array_loader.rs +++ b/crates/shirabe/src/package/loader/array_loader.rs @@ -19,7 +19,7 @@ use chrono::Utc; use indexmap::IndexMap; use shirabe_php_shim::{ AnyThrowable, E_USER_DEPRECATED, PhpMixed, UnexpectedValueException, is_scalar, is_string, - json_encode, ltrim, php_regex, preg_match2, preg_replace, stripos, strpos, strtolower, strval, + json_encode, ltrim, php_regex, preg_match, preg_replace, stripos, strpos, strtolower, strval, substr, trigger_error, trim, }; @@ -339,7 +339,7 @@ impl ArrayLoader { && !shirabe_php_shim::empty(time_value) { let time_str = time_value.as_string().unwrap_or(""); - let time = if preg_match2(php_regex!(r"/^\d++$/D"), time_str, 0).is_some() { + let time = if preg_match(php_regex!(r"/^\d++$/D"), time_str).is_some() { format!("@{}", time_str) } else { time_str.to_string() diff --git a/crates/shirabe/src/package/loader/root_package_loader.rs b/crates/shirabe/src/package/loader/root_package_loader.rs index bc49ffc0..491961a6 100644 --- a/crates/shirabe/src/package/loader/root_package_loader.rs +++ b/crates/shirabe/src/package/loader/root_package_loader.rs @@ -16,7 +16,7 @@ use crate::util::Platform; use crate::util::ProcessExecutor; use indexmap::IndexMap; use shirabe_php_shim::{ - PhpMixed, RuntimeException, UnexpectedValueException, php_regex, preg_match2, preg_replace, + PhpMixed, RuntimeException, UnexpectedValueException, php_regex, preg_match, preg_replace, preg_split, strtolower, }; @@ -252,10 +252,9 @@ impl RootPackageLoader { mut aliases: Vec<IndexMap<String, String>>, ) -> Vec<IndexMap<String, String>> { for (req_name, req_version) in requires { - if let Some(m) = preg_match2( + if let Some(m) = preg_match( php_regex!(r"{(?:^|\| *|, *)([^,\s#|]+)(?:#[^ ]+)? +as +([^,\s|]+)(?:$| *\|| *,)}"), req_version, - 0, ) { let m1 = m.get(1).unwrap_or_default().to_string(); let m2 = m.get(2).unwrap_or_default().to_string(); @@ -317,7 +316,7 @@ impl RootPackageLoader { let mut matched = false; for constraint in &constraints { - if let Some(m) = preg_match2(&pattern, constraint, 0) { + if let Some(m) = preg_match(&pattern, constraint) { let name = strtolower(req_name); let m1 = m.get(1).unwrap_or_default().to_string(); let normalized_m1 = VersionParser::normalize_stability(&m1).unwrap_or_default(); @@ -338,7 +337,7 @@ impl RootPackageLoader { for constraint in &constraints { let req_version_stripped = preg_replace(php_regex!(r"{^([^,\s@]+) as .+$}"), "$1", constraint); - if preg_match2(php_regex!(r"{^[^,\s@]+$}"), &req_version_stripped, 0).is_some() { + if preg_match(php_regex!(r"{^[^,\s@]+$}"), &req_version_stripped).is_some() { let stability_name = VersionParser::parse_stability(&req_version_stripped); if stability_name != "stable" { let name = strtolower(req_name); @@ -363,7 +362,7 @@ impl RootPackageLoader { ) -> IndexMap<String, String> { for (req_name, req_version) in requires { let req_version = preg_replace(php_regex!(r"{^([^,\s@]+) as .+$}"), "$1", req_version); - if let Some(m) = preg_match2(php_regex!(r"{^[^,\s@]+?#([a-f0-9]+)$}"), &req_version, 0) + if let Some(m) = preg_match(php_regex!(r"{^[^,\s@]+?#([a-f0-9]+)$}"), &req_version) && VersionParser::parse_stability(&req_version) == "dev" { let name = strtolower(req_name); diff --git a/crates/shirabe/src/package/loader/validating_array_loader.rs b/crates/shirabe/src/package/loader/validating_array_loader.rs index 5ac1a929..e893756a 100644 --- a/crates/shirabe/src/package/loader/validating_array_loader.rs +++ b/crates/shirabe/src/package/loader/validating_array_loader.rs @@ -10,7 +10,7 @@ use indexmap::IndexMap; use shirabe_php_shim::{ CmpOp, E_USER_DEPRECATED, PHP_EOL, PhpMixed, array_intersect_key, array_values, filter_var_email, get_debug_type, is_array, is_bool, is_int, is_numeric, is_scalar, is_string, - json_encode, parse_url, php_regex, php_to_string, preg_match2, preg_replace, str_replace, + json_encode, parse_url, php_regex, php_to_string, preg_match, preg_replace, str_replace, strcasecmp, strtolower, strtotime, substr, trigger_error, trim, var_export, }; use shirabe_semver::Intervals; @@ -73,12 +73,11 @@ impl ValidatingArrayLoader { return None; } - if preg_match2( + if preg_match( php_regex!( "{^[a-z0-9](?:[_.-]?[a-z0-9]++)*+/[a-z0-9](?:(?:[_.]|-{1,2})?[a-z0-9]++)*+$}iD" ), name, - 0, ) .is_none() { @@ -102,14 +101,14 @@ impl ValidatingArrayLoader { )); } - if preg_match2(php_regex!("{\\.json$}"), name, 0).is_some() { + if preg_match(php_regex!("{\\.json$}"), name).is_some() { return Some(format!( "{} is invalid, package names can not end in .json, consider renaming it or perhaps using a -json suffix instead.", name )); } - if preg_match2(php_regex!("{[A-Z]}"), name, 0).is_some() { + if preg_match(php_regex!("{[A-Z]}"), name).is_some() { if is_link { return Some(format!( "{} is invalid, it should not contain uppercase characters. Please use {} instead.", @@ -143,7 +142,7 @@ impl ValidatingArrayLoader { .as_string() .unwrap_or("") .to_string(); - if preg_match2(format!("{{^{}$}}u", regex), &value, 0).is_none() { + if preg_match(format!("{{^{}$}}u", regex), &value).is_none() { let message = format!( "{} : invalid value ({}), must match {}", property, value, regex @@ -258,7 +257,7 @@ impl ValidatingArrayLoader { if let Some(regex_str) = regex { let value_str = php_to_string(&value); - if preg_match2(format!("{{^{}$}}u", regex_str), &value_str, 0).is_none() { + if preg_match(format!("{{^{}$}}u", regex_str), &value_str).is_none() { self.warnings.borrow_mut().push(format!( "{}.{} : invalid value ({}), must match {}", property, key, value_str, regex_str @@ -1187,8 +1186,7 @@ impl LoaderInterface for ValidatingArrayLoader { self.warnings .borrow_mut() .push(format!("{}.{}", link_type, err)); - } else if preg_match2(php_regex!("{^[A-Za-z0-9_./-]+$}"), &package, 0).is_none() - { + } else if preg_match(php_regex!("{^[A-Za-z0-9_./-]+$}"), &package).is_none() { self.errors.borrow_mut().push(format!( "{}.{} : invalid key, package names must be strings containing only [A-Za-z0-9_./-]", link_type, package @@ -1451,7 +1449,7 @@ impl LoaderInterface for ValidatingArrayLoader { } if let Some(ref_val) = section.get("reference").filter(|_| isset("reference")) { let ref_str = php_to_string(ref_val); - if preg_match2(php_regex!("{^\\s*-}"), &ref_str, 0).is_some() { + if preg_match(php_regex!("{^\\s*-}"), &ref_str).is_some() { self.errors.borrow_mut().push(format!( "{}.reference : must not start with a \"-\", \"{}\" given", src_type, ref_str @@ -1460,7 +1458,7 @@ impl LoaderInterface for ValidatingArrayLoader { } if let Some(url_val) = section.get("url").filter(|_| isset("url")) { let url_str = php_to_string(url_val); - if preg_match2(php_regex!("{^\\s*-}"), &url_str, 0).is_some() { + if preg_match(php_regex!("{^\\s*-}"), &url_str).is_some() { self.errors.borrow_mut().push(format!( "{}.url : must not start with a \"-\", \"{}\" given", src_type, url_str diff --git a/crates/shirabe/src/package/locker.rs b/crates/shirabe/src/package/locker.rs index fee45fef..017bcb6a 100644 --- a/crates/shirabe/src/package/locker.rs +++ b/crates/shirabe/src/package/locker.rs @@ -28,7 +28,7 @@ use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ DATE_RFC3339, LogicException, PhpMixed, RuntimeException, array_intersect, array_keys, array_map, array_merge, file_get_contents, filemtime, function_exists, hash, in_array_loose, - is_int, ksort, php_regex, preg_match2, realpath, strcmp, strtolower, touch2, trim, usort, + is_int, ksort, php_regex, preg_match, realpath, strcmp, strtolower, touch2, trim, usort, }; use shirabe_seld_json_lint::ParsingException; @@ -823,7 +823,7 @@ impl Locker { ), None, ); - if preg_match2(php_regex!(r"{^\s*\d+\s*$}"), &output_str, 0).is_some() { + if preg_match(php_regex!(r"{^\s*\d+\s*$}"), &output_str).is_some() { let ts = trim(&output_str, None).parse::<i64>().unwrap_or(0); datetime = chrono::DateTime::from_timestamp(ts, 0); } @@ -842,10 +842,9 @@ impl Locker { ]), &mut output, path.as_deref(), - )? && let Some(m) = preg_match2( + )? && let Some(m) = preg_match( php_regex!(r"{^\s*(\d+)\s*}"), output.as_string().unwrap_or(""), - 0, ) { let ts = m .get(1) diff --git a/crates/shirabe/src/package/package.rs b/crates/shirabe/src/package/package.rs index ddeb2932..cbc027ba 100644 --- a/crates/shirabe/src/package/package.rs +++ b/crates/shirabe/src/package/package.rs @@ -11,7 +11,7 @@ use crate::util::ComposerMirror; use chrono::{DateTime, Utc}; use indexmap::{IndexMap, IndexSet}; use shirabe_php_shim::{ - E_USER_DEPRECATED, LogicException, PhpMixed, PregMatches, php_regex, preg_match2, preg_replace, + E_USER_DEPRECATED, LogicException, PhpMixed, PregMatches, php_regex, preg_match, preg_replace, preg_replace_callback, strpos, trigger_error, }; @@ -416,13 +416,9 @@ impl Package { // only bitbucket, github and gitlab have auto generated dist URLs that easily allow replacing the reference in the dist URL // TODO generalize this a bit for self-managed/on-prem versions? Some kind of replace token in dist urls which allow this? if self.get_dist_url().is_some() - && preg_match2( - php_regex!( - "{^https?://(?:(?:www\\.)?bitbucket\\.org|(api\\.)?github\\.com|(?:www\\.)?gitlab\\.com)/}i" - ), - &self.get_dist_url().unwrap_or_default(), - 0, - ) + && preg_match(php_regex!( + "{^https?://(?:(?:www\\.)?bitbucket\\.org|(api\\.)?github\\.com|(?:www\\.)?gitlab\\.com)/}i" + ), &self.get_dist_url().unwrap_or_default()) .is_some() { self.set_dist_reference(Some(reference.clone())); diff --git a/crates/shirabe/src/package/version/version_bumper.rs b/crates/shirabe/src/package/version/version_bumper.rs index 50808916..e75dea33 100644 --- a/crates/shirabe/src/package/version/version_bumper.rs +++ b/crates/shirabe/src/package/version/version_bumper.rs @@ -6,7 +6,7 @@ use crate::package::loader::ArrayLoader; use crate::package::version::VersionParser; use crate::util::Platform; use shirabe_php_shim::{ - CaptureKey, php_regex, preg_match_all_offset_capture, preg_match2, preg_replace, + CaptureKey, php_regex, preg_match, preg_match_all_offset_capture, preg_replace, }; use shirabe_semver::Intervals; use shirabe_semver::constraint::AnyConstraint; @@ -51,7 +51,7 @@ impl VersionBumper { preg_replace(php_regex!(r"{(?:\.(?:0|9999999))+(-dev)?$}"), "", &version); let new_pretty_constraint = format!("^{}", version_without_suffix); - if preg_match2(php_regex!(r"{^\^\d+(\.\d+)*$}"), &new_pretty_constraint, 0).is_none() { + if preg_match(php_regex!(r"{^\^\d+(\.\d+)*$}"), &new_pretty_constraint).is_none() { return Ok(pretty_constraint); } diff --git a/crates/shirabe/src/package/version/version_guesser.rs b/crates/shirabe/src/package/version/version_guesser.rs index fd7fe389..668fce02 100644 --- a/crates/shirabe/src/package/version/version_guesser.rs +++ b/crates/shirabe/src/package/version/version_guesser.rs @@ -14,7 +14,7 @@ use crate::util::sync_executor; use indexmap::IndexMap; use shirabe_php_shim::{ PhpMixed, RuntimeException, array_keys, array_map, array_merge, empty, function_exists, - implode, is_string, json_encode, php_regex, preg_match2, preg_quote, preg_replace, str_replace, + implode, is_string, json_encode, php_regex, preg_match, preg_quote, preg_replace, str_replace, strlen, strnatcasecmp, strpos, substr, trim, usort, }; @@ -156,10 +156,9 @@ impl VersionGuesser { } if "-dev" == substr(version_data.version.as_deref().unwrap_or(""), -4, None) - && preg_match2( + && preg_match( php_regex!(r"{\.9{7}}"), version_data.version.as_deref().unwrap_or(""), - 0, ) .is_some() { @@ -182,10 +181,9 @@ impl VersionGuesser { -4, None, ) - && preg_match2( + && preg_match( php_regex!(r"{\.9{7}}"), version_data.feature_version.as_deref().unwrap_or(""), - 0, ) .is_some() { @@ -232,12 +230,11 @@ impl VersionGuesser { // find current branch and collect all branch names for branch in self.process.borrow().split_lines(&output) { if !branch.is_empty() - && let Some(m) = preg_match2( + && let Some(m) = preg_match( php_regex!( r"{^(?:\* ) *(\(no branch\)|\(detached from \S+\)|\(HEAD detached at \S+\)|\S+) *([a-f0-9]+) .*$}" ), &branch, - 0, ) { let g1 = m.get(1).unwrap_or_default().to_string(); @@ -260,13 +257,12 @@ impl VersionGuesser { } if !branch.is_empty() - && preg_match2(php_regex!(r"{^ *.+/HEAD }"), &branch, 0).is_none() - && let Some(m) = preg_match2( + && preg_match(php_regex!(r"{^ *.+/HEAD }"), &branch).is_none() + && let Some(m) = preg_match( php_regex!( r"{^(?:\* )? *((?:remotes/(?:origin|upstream)/)?[^\s/]+) *([a-f0-9]+) .*$}" ), &branch, - 0, ) { branches.push(m.get(1).unwrap_or_default().to_string()); @@ -612,10 +608,10 @@ impl VersionGuesser { non_feature_branches = implode("|", &names); } - preg_match2(format!( + preg_match(format!( r"{{^({}|master|main|latest|next|current|support|tip|trunk|default|develop|\d+\..+)$}}", non_feature_branches, - ), branch_name.unwrap_or(""), 0).is_none() + ), branch_name.unwrap_or("")).is_none() } fn guess_fossil_version(&mut self, path: &str) -> anyhow::Result<VersionData> { @@ -698,7 +694,7 @@ impl VersionGuesser { trunk_path, branches_path, tags_path, ); - if let Some(matches) = preg_match2(&url_pattern, &output, 0) { + if let Some(matches) = preg_match(&url_pattern, &output) { let m1 = matches.get(1).unwrap_or_default(); let m2 = matches.get(2); let m3 = matches.get(3); @@ -751,7 +747,7 @@ impl VersionGuesser { .into()); } }; - if let Some(m) = preg_match2(php_regex!(r"{^(\d+(?:\.\d+)*)-dev$}i"), &version, 0) { + if let Some(m) = preg_match(php_regex!(r"{^(\d+(?:\.\d+)*)-dev$}i"), &version) { return Ok(format!("{}.x-dev", m.get(1).unwrap_or_default())); } diff --git a/crates/shirabe/src/package/version/version_parser.rs b/crates/shirabe/src/package/version/version_parser.rs index ad1a05cf..6e7c5825 100644 --- a/crates/shirabe/src/package/version/version_parser.rs +++ b/crates/shirabe/src/package/version/version_parser.rs @@ -2,7 +2,7 @@ use crate::repository::PlatformRepository; use indexmap::IndexMap; -use shirabe_php_shim::{php_regex, preg_match2, preg_replace}; +use shirabe_php_shim::{php_regex, preg_match, preg_replace}; use shirabe_semver::Semver; use shirabe_semver::VersionParser as SemverVersionParser; use shirabe_semver::constraint::AnyConstraint; @@ -57,10 +57,9 @@ impl VersionParser { if !pair.contains(' ') && i + 1 < count && !pairs[i + 1].contains('/') - && preg_match2( + && preg_match( php_regex!(r"{(?<=[a-z0-9_/-])\*|\*(?=[a-z0-9_/-])}i"), &pairs[i + 1], - 0, ) .is_none() && !PlatformRepository::is_platform_package(&pairs[i + 1]) diff --git a/crates/shirabe/src/package/version/version_selector.rs b/crates/shirabe/src/package/version/version_selector.rs index c7b7b31e..91929c40 100644 --- a/crates/shirabe/src/package/version/version_selector.rs +++ b/crates/shirabe/src/package/version/version_selector.rs @@ -16,7 +16,7 @@ use crate::repository::PlatformRepository; use crate::repository::RepositoryInterface; use crate::repository::RepositorySetInterface; use indexmap::IndexMap; -use shirabe_php_shim::{CmpOp, php_regex, preg_match2, preg_replace, strtolower, version_compare}; +use shirabe_php_shim::{CmpOp, php_regex, preg_match, preg_replace, strtolower, version_compare}; use shirabe_semver::constraint::AnyConstraint; use shirabe_semver::constraint::SimpleConstraint; @@ -302,7 +302,7 @@ impl VersionSelector { let semantic_version_parts: Vec<&str> = version.split('.').collect(); if semantic_version_parts.len() == 4 - && preg_match2(php_regex!(r"{^\d+\D?}"), semantic_version_parts[3], 0).is_some() + && preg_match(php_regex!(r"{^\d+\D?}"), semantic_version_parts[3]).is_some() { let mut parts: Vec<String> = semantic_version_parts .iter() diff --git a/crates/shirabe/src/platform/version.rs b/crates/shirabe/src/platform/version.rs index baa029ef..b9573366 100644 --- a/crates/shirabe/src/platform/version.rs +++ b/crates/shirabe/src/platform/version.rs @@ -1,6 +1,6 @@ //! ref: composer/src/Composer/Platform/Version.php -use shirabe_php_shim::{CmpOp, php_regex, preg_match2, version_compare}; +use shirabe_php_shim::{CmpOp, php_regex, preg_match, version_compare}; pub struct Version; @@ -8,12 +8,11 @@ impl Version { pub fn parse_openssl(openssl_version: &str, is_fips: &mut bool) -> Option<String> { *is_fips = false; - let matches = preg_match2( + let matches = preg_match( php_regex!( r"/^(?P<version>[0-9.]+)(?P<patch>[a-z]{0,2})(?P<suffix>(?:-?(?:dev|pre|alpha|beta|rc|fips)[\d]*)*)(?:-\w+)?(?: \(.+?\))?$/" ), openssl_version, - 0, )?; let version = matches.name("version").unwrap_or_default().to_string(); @@ -42,10 +41,9 @@ impl Version { } pub fn parse_libjpeg(libjpeg_version: &str) -> Option<String> { - let matches = preg_match2( + let matches = preg_match( php_regex!(r"/^(?P<major>\d+)(?P<minor>[a-z]*)$/"), libjpeg_version, - 0, )?; let major = matches.name("major").unwrap_or_default().to_string(); @@ -58,10 +56,9 @@ impl Version { } pub fn parse_zoneinfo_version(zoneinfo_version: &str) -> Option<String> { - let matches = preg_match2( + let matches = preg_match( php_regex!(r"/^(?P<year>\d{4})(?P<revision>[a-z]*)$/"), zoneinfo_version, - 0, )?; let year = matches.name("year").unwrap_or_default().to_string(); diff --git a/crates/shirabe/src/plugin/plugin_manager.rs b/crates/shirabe/src/plugin/plugin_manager.rs index 5c2c5bff..28616903 100644 --- a/crates/shirabe/src/plugin/plugin_manager.rs +++ b/crates/shirabe/src/plugin/plugin_manager.rs @@ -28,7 +28,7 @@ use indexmap::IndexMap; use shirabe_php_rpc::{PluginValue, call_function_with_dispatcher}; use shirabe_php_shim::{ CmpOp, E_USER_DEPRECATED, PhpMixed, RuntimeException, UnexpectedValueException, dirname, empty, - file_get_contents, implode, ksort, php_regex, preg_match2, preg_quote, preg_replace2, strrpos, + file_get_contents, implode, ksort, php_regex, preg_match, preg_quote, preg_replace2, strrpos, strtr_array, substr, trigger_error, trim, var_export, var_export_str, version_compare, }; use shirabe_semver::constraint::SimpleConstraint; @@ -259,7 +259,7 @@ impl PluginManager { } if package.get_name() == "symfony/flex" - && preg_match2(php_regex!("{^[0-9.]+$}"), &package.get_version(), 0).is_some() + && preg_match(php_regex!("{^[0-9.]+$}"), &package.get_version()).is_some() && version_compare(&package.get_version(), "1.9.8", CmpOp::Lt) { self.io.write_error(&format!("<warning>The \"{}\" plugin {}was skipped because it is not compatible with Composer 2+. Make sure to update it to version 1.9.8 or greater.</warning>", @@ -1242,7 +1242,7 @@ impl PluginManager { .map(|(k, v)| (k.clone(), *v)) .collect(); for (pattern, allow) in &rules_snapshot { - if preg_match2(pattern, package, 0).is_some() { + if preg_match(pattern, package).is_some() { return Ok(*allow); } } diff --git a/crates/shirabe/src/question/strict_confirmation_question.rs b/crates/shirabe/src/question/strict_confirmation_question.rs index f1240336..dbc39574 100644 --- a/crates/shirabe/src/question/strict_confirmation_question.rs +++ b/crates/shirabe/src/question/strict_confirmation_question.rs @@ -1,6 +1,6 @@ //! ref: composer/src/Composer/Question/StrictConfirmationQuestion.php -use shirabe_php_shim::{PhpMixed, empty, is_bool, preg_match2}; +use shirabe_php_shim::{PhpMixed, empty, is_bool, preg_match}; use shirabe_symfony_console::exception::InvalidArgumentException; use shirabe_symfony_console::question::Question; use shirabe_symfony_console::question::QuestionInterface; @@ -53,10 +53,10 @@ impl StrictConfirmationQuestion { return default.clone(); } if let PhpMixed::String(s) = &answer { - if preg_match2(&true_regex, s, 0).is_some() { + if preg_match(&true_regex, s).is_some() { return PhpMixed::Bool(true); } - if preg_match2(&false_regex, s, 0).is_some() { + if preg_match(&false_regex, s).is_some() { return PhpMixed::Bool(false); } } diff --git a/crates/shirabe/src/repository/array_repository.rs b/crates/shirabe/src/repository/array_repository.rs index 2e364d0e..b475b0e0 100644 --- a/crates/shirabe/src/repository/array_repository.rs +++ b/crates/shirabe/src/repository/array_repository.rs @@ -12,7 +12,7 @@ use crate::repository::{ RepositoryInterfaceHandle, RepositoryInterfaceWeakHandle, SearchResult, }; use indexmap::IndexMap; -use shirabe_php_shim::{implode, php_regex, preg_match2, preg_quote, preg_split, strtolower}; +use shirabe_php_shim::{implode, php_regex, preg_match, preg_quote, preg_split, strtolower}; use shirabe_semver::constraint::AnyConstraint; use shirabe_semver::constraint::SimpleConstraint; use std::rc::Weak; @@ -357,7 +357,7 @@ impl RepositoryInterface for ArrayRepository { let fulltext_match = mode == crate::repository::SEARCH_FULLTEXT && complete.is_some() - && preg_match2( + && preg_match( ®ex, &format!( "{} {}", @@ -368,11 +368,10 @@ impl RepositoryInterface for ArrayRepository { .get_description() .unwrap_or_default() ), - 0, ) .is_some(); - if preg_match2(®ex, &name, 0).is_some() || fulltext_match { + if preg_match(®ex, &name).is_some() || fulltext_match { if mode == crate::repository::SEARCH_VENDOR { matches.insert( name.clone(), diff --git a/crates/shirabe/src/repository/composer_repository.rs b/crates/shirabe/src/repository/composer_repository.rs index 9f6e6bf8..fbf9f767 100644 --- a/crates/shirabe/src/repository/composer_repository.rs +++ b/crates/shirabe/src/repository/composer_repository.rs @@ -43,7 +43,7 @@ use shirabe_php_shim::{ json_decode_assoc, parse_url, php_regex, preg_split, realpath, strtolower, strtr, urlencode, var_export, }; -use shirabe_php_shim::{Catch as _, preg_grep, preg_match2, preg_replace}; +use shirabe_php_shim::{Catch as _, preg_grep, preg_match, preg_replace}; use shirabe_semver::CompilingMatcher; use shirabe_semver::constraint::AnyConstraint; use shirabe_semver::constraint::MatchAllConstraint; @@ -161,7 +161,7 @@ impl ComposerRepository { .and_then(|v| v.as_string()) .unwrap_or("") .to_string(); - if preg_match2(php_regex!(r"{^[\w.]+\??://}"), &url_str, 0).is_none() { + if preg_match(php_regex!(r"{^[\w.]+\??://}"), &url_str).is_none() { if let Some(local_file_path) = realpath(&url_str) { // it is a local path, add file scheme repo_config.insert( @@ -244,10 +244,9 @@ impl ComposerRepository { .to_string(); // force url for packagist.org to repo.packagist.org - if let Some(match_packagist) = preg_match2( + if let Some(match_packagist) = preg_match( php_regex!(r"{^(?P<proto>https?)://packagist\.org/?$}i"), &url, - 0, ) { let proto = match_packagist .name("proto") @@ -779,10 +778,9 @@ impl ComposerRepository { if self.has_providers()? || self.lazy_providers_url.is_some() { // optimize search for "^foo/bar" where at least "^foo/" is present by loading this directly from the listUrl if present - if let Some(match_groups) = preg_match2( + if let Some(match_groups) = preg_match( php_regex!(r"{^\^(?P<query>(?P<vendor>[a-z0-9_.-]+)/[a-z0-9_.-]*)\*?$}i"), &query, - 0, ) && let Some(list_url) = self.list_url.as_ref() { let q = match_groups.name("query").unwrap_or_default().to_string(); @@ -2421,7 +2419,7 @@ impl ComposerRepository { } if url.starts_with('/') { - if let Some(matches) = preg_match2(php_regex!(r"{^[^:]++://[^/]*+}"), &self.url, 0) { + if let Some(matches) = preg_match(php_regex!(r"{^[^:]++://[^/]*+}"), &self.url) { return Ok(format!("{}{}", matches.get(0).unwrap_or_default(), url)); } @@ -2710,7 +2708,7 @@ impl ComposerRepository { // url-encode $ signs in URLs as bad proxies choke on them if let Some(pos) = filename.find('$') && pos > 0 - && preg_match2(php_regex!(r"{^https?://}i"), &filename, 0).is_some() + && preg_match(php_regex!(r"{^https?://}i"), &filename).is_some() { filename = format!("{}%24{}", &filename[..pos], &filename[pos + 1..]); } @@ -3309,7 +3307,7 @@ impl ComposerRepository { if let Some(ref patterns) = self.available_package_patterns { for provider_regex in patterns.iter() { - if preg_match2(provider_regex, name, 0).is_some() { + if preg_match(provider_regex, name).is_some() { return Ok(true); } } diff --git a/crates/shirabe/src/repository/filter_repository.rs b/crates/shirabe/src/repository/filter_repository.rs index 3b36a969..77236a21 100644 --- a/crates/shirabe/src/repository/filter_repository.rs +++ b/crates/shirabe/src/repository/filter_repository.rs @@ -9,7 +9,7 @@ use crate::repository::{ RepositoryInterfaceHandle, SearchResult, }; use indexmap::IndexMap; -use shirabe_php_shim::{InvalidArgumentException, PhpMixed, preg_match2}; +use shirabe_php_shim::{InvalidArgumentException, PhpMixed, preg_match}; use shirabe_semver::constraint::AnyConstraint; #[derive(Debug)] @@ -123,14 +123,14 @@ impl FilterRepository { } if let Some(only) = &self.only { - return preg_match2(only, name, 0).is_some(); + return preg_match(only, name).is_some(); } if self.exclude.is_none() { return true; } - preg_match2(self.exclude.as_ref().unwrap(), name, 0).is_none() + preg_match(self.exclude.as_ref().unwrap(), name).is_none() } } diff --git a/crates/shirabe/src/repository/path_repository.rs b/crates/shirabe/src/repository/path_repository.rs index 77cc0222..3d36f65c 100644 --- a/crates/shirabe/src/repository/path_repository.rs +++ b/crates/shirabe/src/repository/path_repository.rs @@ -25,7 +25,7 @@ use crate::util::Url; use indexmap::IndexMap; use shirabe_php_shim::{ GLOB_BRACE, GLOB_MARK, GLOB_ONLYDIR, PhpMixed, RuntimeException, defined, file_exists, - file_get_contents, glob_with_flags, hash, php_regex, preg_match2, realpath, serialize, + file_get_contents, glob_with_flags, hash, php_regex, preg_match, realpath, serialize, }; #[derive(Debug)] @@ -158,9 +158,9 @@ impl PathRepository { let url_matches = self.get_url_matches()?; if url_matches.is_empty() { - if preg_match2(php_regex!(r"{[*{}]}"), &self.url, 0).is_some() { + if preg_match(php_regex!(r"{[*{}]}"), &self.url).is_some() { let mut url = self.url.clone(); - while preg_match2(php_regex!(r"{[*{}]}"), &url, 0).is_some() { + while preg_match(php_regex!(r"{[*{}]}"), &url).is_some() { url = shirabe_php_shim::dirname(&url); } // the parent directory before any wildcard exists, so we assume it is correctly configured but simply empty diff --git a/crates/shirabe/src/repository/platform_repository.rs b/crates/shirabe/src/repository/platform_repository.rs index 4ded0163..839d17d6 100644 --- a/crates/shirabe/src/repository/platform_repository.rs +++ b/crates/shirabe/src/repository/platform_repository.rs @@ -19,7 +19,7 @@ use indexmap::IndexMap; use shirabe_php_rpc::PlatformInfo; use shirabe_php_shim::{ InvalidArgumentException, PhpMixed, UnexpectedValueException, array_map_str_fn, - array_slice_strs, explode, get_class, implode, is_string, php_regex, preg_match2, preg_replace, + array_slice_strs, explode, get_class, implode, is_string, php_regex, preg_match, preg_replace, str_replace, strpos, strtolower, var_export, }; use shirabe_semver::constraint::SimpleConstraint; @@ -315,10 +315,9 @@ impl PlatformRepository { let info = platform_info.get_extension_info(name); // librabbitmq version => 0.9.0 - if let Some(librabbitmq_matches) = preg_match2( + if let Some(librabbitmq_matches) = preg_match( php_regex!("/^librabbitmq version => (?<version>.+)$/im"), info, - 0, ) { self.add_library( &mut libraries, @@ -331,10 +330,9 @@ impl PlatformRepository { } // AMQP protocol version => 0-9-1 - if let Some(protocol_matches) = preg_match2( + if let Some(protocol_matches) = preg_match( php_regex!("/^AMQP protocol version => (?<version>.+)$/im"), info, - 0, ) { let version_str = protocol_matches .name("version") @@ -356,7 +354,7 @@ impl PlatformRepository { // BZip2 Version => 1.0.6, 6-Sept-2010 if let Some(matches) = - preg_match2(php_regex!("/^BZip2 Version => (?<version>.*),/im"), info, 0) + preg_match(php_regex!("/^BZip2 Version => (?<version>.*),/im"), info) { self.add_library( &mut libraries, @@ -383,10 +381,9 @@ impl PlatformRepository { let info = platform_info.get_extension_info(name); // SSL Version => OpenSSL/1.0.1t - if let Some(ssl_matches) = preg_match2( + if let Some(ssl_matches) = preg_match( php_regex!("{^SSL Version => (?<library>[^/]+)/(?<version>.+)$}im"), info, - 0, ) { let ssl_library_raw = ssl_matches.name("library").unwrap_or_default().to_string(); @@ -413,10 +410,9 @@ impl PlatformRepository { } else { let (shortlib, ssl_lib); if library.starts_with("(securetransport)") { - if let Some(securetransport_matches) = preg_match2( + if let Some(securetransport_matches) = preg_match( php_regex!("{^\\(securetransport\\) ([a-z0-9]+)}"), &library, - 0, ) { shortlib = "securetransport".to_string(); let m1 = securetransport_matches @@ -444,12 +440,11 @@ impl PlatformRepository { } // libSSH Version => libssh2/1.4.3 - if let Some(ssh_matches) = preg_match2( + if let Some(ssh_matches) = preg_match( php_regex!( "{^libSSH Version => (?<library>[^/]+)/(?<version>.+?)(?:/.*)?$}im" ), info, - 0, ) { let ssh_library = ssh_matches.name("library").unwrap_or_default().to_string(); @@ -467,7 +462,7 @@ impl PlatformRepository { // ZLib Version => 1.2.8 if let Some(zlib_matches) = - preg_match2(php_regex!("{^ZLib Version => (?<version>.+)$}im"), info, 0) + preg_match(php_regex!("{^ZLib Version => (?<version>.+)$}im"), info) { self.add_library( &mut libraries, @@ -484,11 +479,9 @@ impl PlatformRepository { let info = platform_info.get_extension_info(name); // timelib version => 2018.03 - if let Some(timelib_matches) = preg_match2( - php_regex!("/^timelib version => (?<version>.+)$/im"), - info, - 0, - ) { + if let Some(timelib_matches) = + preg_match(php_regex!("/^timelib version => (?<version>.+)$/im"), info) + { self.add_library( &mut libraries, &format!("{}-timelib", name), @@ -500,21 +493,19 @@ impl PlatformRepository { } // Timezone Database => internal - if let Some(zoneinfo_source_matches) = preg_match2( + if let Some(zoneinfo_source_matches) = preg_match( php_regex!("/^Timezone Database => (?<source>internal|external)$/im"), info, - 0, ) { let external = zoneinfo_source_matches .name("source") .map(|s| s == "external") .unwrap_or(false); - if let Some(zoneinfo_matches) = preg_match2( + if let Some(zoneinfo_matches) = preg_match( php_regex!( "/^\"Olson\" Timezone Database Version => (?<version>.+?)(?:\\.system)?$/im" ), info, - 0, ) { let zoneinfo_version = zoneinfo_matches .name("version") @@ -551,7 +542,7 @@ impl PlatformRepository { // libmagic => 537 if let Some(magic_matches) = - preg_match2(php_regex!("/^libmagic => (?<version>.+)$/im"), info, 0) + preg_match(php_regex!("/^libmagic => (?<version>.+)$/im"), info) { self.add_library( &mut libraries, @@ -581,10 +572,9 @@ impl PlatformRepository { let info = platform_info.get_extension_info(name); - if let Some(libjpeg_matches) = preg_match2( + if let Some(libjpeg_matches) = preg_match( php_regex!("/^libJPEG Version => (?<version>.+?)(?: compatible)?$/im"), info, - 0, ) { let libjpeg_version = libjpeg_matches .name("version") @@ -601,11 +591,9 @@ impl PlatformRepository { )?; } - if let Some(libpng_matches) = preg_match2( - php_regex!("/^libPNG Version => (?<version>.+)$/im"), - info, - 0, - ) { + if let Some(libpng_matches) = + preg_match(php_regex!("/^libPNG Version => (?<version>.+)$/im"), info) + { self.add_library( &mut libraries, &format!("{}-libpng", name), @@ -616,11 +604,9 @@ impl PlatformRepository { )?; } - if let Some(freetype_matches) = preg_match2( - php_regex!("/^FreeType Version => (?<version>.+)$/im"), - info, - 0, - ) { + if let Some(freetype_matches) = + preg_match(php_regex!("/^FreeType Version => (?<version>.+)$/im"), info) + { self.add_library( &mut libraries, &format!("{}-freetype", name), @@ -631,10 +617,9 @@ impl PlatformRepository { )?; } - if let Some(libxpm_matches) = preg_match2( + if let Some(libxpm_matches) = preg_match( php_regex!("/^libXpm Version => (?<versionId>\\d+)$/im"), info, - 0, ) { let version_id: i64 = libxpm_matches .name("versionId") @@ -705,7 +690,7 @@ impl PlatformRepository { )?; } else { if let Some(matches) = - preg_match2(php_regex!("/^ICU version => (?<version>.+)$/im"), info, 0) + preg_match(php_regex!("/^ICU version => (?<version>.+)$/im"), info) { self.add_library( &mut libraries, @@ -719,10 +704,9 @@ impl PlatformRepository { } // ICU TZData version => 2019c - if let Some(zoneinfo_matches) = preg_match2( + if let Some(zoneinfo_matches) = preg_match( php_regex!("/^ICU TZData version => (?<version>.*)$/im"), info, - 0, ) { let zi_version = zoneinfo_matches .name("version") @@ -783,10 +767,9 @@ impl PlatformRepository { Self::imagick_get_version_string(image_magick_version); // 6.x: ImageMagick 6.2.9 08/24/06 Q16 http://www.imagemagick.org // 7.x: ImageMagick 7.0.8-34 Q16 x86_64 2019-03-23 https://imagemagick.org - if let Some(matches) = preg_match2( + if let Some(matches) = preg_match( php_regex!("/^ImageMagick (?<version>[\\d.]+)(?:-(?<patch>\\d+))?/"), &image_magick_version_str, - 0, ) { let mut version_built = matches.name("version").unwrap_or_default().to_string(); @@ -808,12 +791,11 @@ impl PlatformRepository { "ldap" => { let info = platform_info.get_extension_info(name); - if let Some(matches) = preg_match2( + if let Some(matches) = preg_match( php_regex!("/^Vendor Version => (?<versionId>\\d+)$/im"), info, - 0, ) && let Some(vendor_matches) = - preg_match2(php_regex!("/^Vendor Name => (?<vendor>.+)$/im"), info, 0) + preg_match(php_regex!("/^Vendor Name => (?<vendor>.+)$/im"), info) { let version_id: i64 = matches .name("versionId") @@ -864,11 +846,9 @@ impl PlatformRepository { let info = platform_info.get_extension_info(name); // libmbfl version => 1.3.2 - if let Some(libmbfl_matches) = preg_match2( - php_regex!("/^libmbfl version => (?<version>.+)$/im"), - info, - 0, - ) { + if let Some(libmbfl_matches) = + preg_match(php_regex!("/^libmbfl version => (?<version>.+)$/im"), info) + { self.add_library( &mut libraries, &format!("{}-libmbfl", name), @@ -897,12 +877,11 @@ impl PlatformRepository { // Multibyte regex (oniguruma) version => 5.9.5 // oniguruma version => 6.9.0 } else { - if let Some(oniguruma_matches) = preg_match2( + if let Some(oniguruma_matches) = preg_match( php_regex!( "/^(?:oniguruma|Multibyte regex \\(oniguruma\\)) version => (?<version>.+)$/im" ), info, - 0, ) { self.add_library( &mut libraries, @@ -920,10 +899,9 @@ impl PlatformRepository { let info = platform_info.get_extension_info(name); // libmemcached version => 1.0.18 - if let Some(matches) = preg_match2( + if let Some(matches) = preg_match( php_regex!("/^libmemcached version => (?<version>.+)$/im"), info, - 0, ) { self.add_library( &mut libraries, @@ -943,10 +921,9 @@ impl PlatformRepository { _ => "".to_string(), }; // OpenSSL 1.1.1g 21 Apr 2020 - if let Some(matches) = preg_match2( + if let Some(matches) = preg_match( php_regex!("{^(?:OpenSSL|LibreSSL)?\\s*(?<version>\\S+)}i"), &openssl_text_str, - 0, ) { let version = matches.name("version").unwrap_or_default().to_string(); let mut is_fips = false; @@ -979,10 +956,9 @@ impl PlatformRepository { let info = platform_info.get_extension_info(name); // PCRE Unicode Version => 12.1.0 - if let Some(pcre_unicode_matches) = preg_match2( + if let Some(pcre_unicode_matches) = preg_match( php_regex!("/^PCRE Unicode Version => (?<version>.+)$/im"), info, - 0, ) { self.add_library( &mut libraries, @@ -998,12 +974,11 @@ impl PlatformRepository { "mysqlnd" | "pdo_mysql" => { let info = platform_info.get_extension_info(name); - if let Some(matches) = preg_match2( + if let Some(matches) = preg_match( php_regex!( "/^(?:Client API version|Version) => mysqlnd (?<version>.+?) /mi" ), info, - 0, ) { self.add_library( &mut libraries, @@ -1019,10 +994,9 @@ impl PlatformRepository { "mongodb" => { let info = platform_info.get_extension_info(name); - if let Some(libmongoc_matches) = preg_match2( + if let Some(libmongoc_matches) = preg_match( php_regex!("/^libmongoc bundled version => (?<version>.+)$/im"), info, - 0, ) { self.add_library( &mut libraries, @@ -1034,10 +1008,9 @@ impl PlatformRepository { )?; } - if let Some(libbson_matches) = preg_match2( + if let Some(libbson_matches) = preg_match( php_regex!("/^libbson bundled version => (?<version>.+)$/im"), info, - 0, ) { self.add_library( &mut libraries, @@ -1069,10 +1042,9 @@ impl PlatformRepository { // intentional fall-through to next case... let info = platform_info.get_extension_info(name); - if let Some(matches) = preg_match2( + if let Some(matches) = preg_match( php_regex!("/^PostgreSQL\\(libpq\\) Version => (?<version>.*)$/im"), info, - 0, ) { self.add_library( &mut libraries, @@ -1089,10 +1061,9 @@ impl PlatformRepository { "pdo_pgsql" => { let info = platform_info.get_extension_info(name); - if let Some(matches) = preg_match2( + if let Some(matches) = preg_match( php_regex!("/^PostgreSQL\\(libpq\\) Version => (?<version>.*)$/im"), info, - 0, ) { self.add_library( &mut libraries, @@ -1110,10 +1081,9 @@ impl PlatformRepository { // Used Library => Compiled => Linked // libpq => 14.3 (Ubuntu 14.3-1.pgdg22.04+1) => 15.0.2 - if let Some(matches) = preg_match2( + if let Some(matches) = preg_match( php_regex!("/^libpq => (?<compiled>.+) => (?<linked>.+)$/im"), info, - 0, ) { self.add_library( &mut libraries, @@ -1185,11 +1155,9 @@ impl PlatformRepository { "sqlite3" | "pdo_sqlite" => { let info = platform_info.get_extension_info(name); - if let Some(matches) = preg_match2( - php_regex!("/^SQLite Library => (?<version>.+)$/im"), - info, - 0, - ) { + if let Some(matches) = + preg_match(php_regex!("/^SQLite Library => (?<version>.+)$/im"), info) + { self.add_library( &mut libraries, &format!("{}-sqlite", name), @@ -1204,11 +1172,9 @@ impl PlatformRepository { "ssh2" => { let info = platform_info.get_extension_info(name); - if let Some(matches) = preg_match2( - php_regex!("/^libssh2 version => (?<version>.+)$/im"), - info, - 0, - ) { + if let Some(matches) = + preg_match(php_regex!("/^libssh2 version => (?<version>.+)$/im"), info) + { self.add_library( &mut libraries, &format!("{}-libssh2", name), @@ -1237,12 +1203,11 @@ impl PlatformRepository { )?; let info = platform_info.get_extension_info("xsl"); - if let Some(matches) = preg_match2( + if let Some(matches) = preg_match( php_regex!( "/^libxslt compiled against libxml Version => (?<version>.+)$/im" ), info, - 0, ) { self.add_library( &mut libraries, @@ -1258,11 +1223,9 @@ impl PlatformRepository { "yaml" => { let info = platform_info.get_extension_info("yaml"); - if let Some(matches) = preg_match2( - php_regex!("/^LibYAML Version => (?<version>.+)$/im"), - info, - 0, - ) { + if let Some(matches) = + preg_match(php_regex!("/^LibYAML Version => (?<version>.+)$/im"), info) + { self.add_library( &mut libraries, &format!("{}-libyaml", name), @@ -1312,11 +1275,9 @@ impl PlatformRepository { // Linked Version => 1.2.8 } else { let info = platform_info.get_extension_info(name); - if let Some(matches) = preg_match2( - php_regex!("/^Linked Version => (?<version>.+)$/im"), - info, - 0, - ) { + if let Some(matches) = + preg_match(php_regex!("/^Linked Version => (?<version>.+)$/im"), info) + { self.add_library( &mut libraries, name, @@ -1512,10 +1473,9 @@ impl PlatformRepository { Ok(v) => v, Err(_) => { extra_description = Some(format!(" (actual version: {})", pretty_version)); - if let Some(m) = preg_match2( + if let Some(m) = preg_match( php_regex!("{^(\\d+\\.\\d+\\.\\d+(?:\\.\\d+)?)}"), &pretty_version, - 0, ) { pretty_version = m.get(1).unwrap_or_default().to_string(); } else { @@ -1644,7 +1604,7 @@ impl PlatformRepository { return cached; } - let result = preg_match2(Self::PLATFORM_PACKAGE_REGEX, name, 0).is_some(); + let result = preg_match(Self::PLATFORM_PACKAGE_REGEX, name).is_some(); cache.insert(name.to_string(), result); result } diff --git a/crates/shirabe/src/repository/vcs/forgejo_driver.rs b/crates/shirabe/src/repository/vcs/forgejo_driver.rs index 90480add..4238be8f 100644 --- a/crates/shirabe/src/repository/vcs/forgejo_driver.rs +++ b/crates/shirabe/src/repository/vcs/forgejo_driver.rs @@ -17,7 +17,7 @@ use crate::util::http::Response; use indexmap::IndexMap; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ - PhpMixed, RuntimeException, base64_decode, explode, extension_loaded, php_regex, preg_match2, + PhpMixed, RuntimeException, base64_decode, explode, extension_loaded, php_regex, preg_match, urlencode, }; @@ -584,7 +584,7 @@ impl ForgejoDriver { let links = explode(",", &header); for link in links { - if let Some(m) = preg_match2(php_regex!(r#"{<(.+?)>; *rel="next"}"#), &link, 0) + if let Some(m) = preg_match(php_regex!(r#"{<(.+?)>; *rel="next"}"#), &link) && let Some(url) = m.get(1) { return Some(url.to_string()); diff --git a/crates/shirabe/src/repository/vcs/fossil_driver.rs b/crates/shirabe/src/repository/vcs/fossil_driver.rs index c42ca271..d5a9334f 100644 --- a/crates/shirabe/src/repository/vcs/fossil_driver.rs +++ b/crates/shirabe/src/repository/vcs/fossil_driver.rs @@ -13,7 +13,7 @@ use chrono::{DateTime, FixedOffset, Utc}; use indexmap::IndexMap; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ - PhpMixed, RuntimeException, dirname, is_dir, is_file, is_writable, php_regex, preg_match2, + PhpMixed, RuntimeException, dirname, is_dir, is_file, is_writable, php_regex, preg_match, preg_replace, }; @@ -301,17 +301,16 @@ impl FossilDriver { url: &str, deep: bool, ) -> anyhow::Result<bool> { - if preg_match2( + if preg_match( php_regex!(r"#(^(?:https?|ssh)://(?:[^@]@)?(?:chiselapp\.com|fossil\.))#i"), url, - 0, ) .is_some() { return Ok(true); } - if preg_match2(php_regex!(r"!/fossil/|\.fossil!"), url, 0).is_some() { + if preg_match(php_regex!(r"!/fossil/|\.fossil!"), url).is_some() { return Ok(true); } diff --git a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs index 9f8e7a80..a05e9835 100644 --- a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs +++ b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs @@ -19,7 +19,7 @@ use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ InvalidArgumentException, LogicException, PhpMixed, RuntimeException, array_key_exists, array_search_mixed, extension_loaded, http_build_query, implode, is_array, php_regex, - preg_match2, preg_replace, strpos, + preg_match, preg_replace, strpos, }; #[derive(Debug)] @@ -84,10 +84,9 @@ impl GitBitbucketDriver { /// @inheritDoc pub fn initialize(&mut self) -> anyhow::Result<()> { - let Some(m) = preg_match2( + let Some(m) = preg_match( php_regex!(r"#^https?://bitbucket\.org/([^/]+)/([^/]+?)(?:\.git|/?)?$#i"), &self.inner.url, - 0, ) else { return Err(InvalidArgumentException::new(format!( "The Bitbucket repository URL {} is invalid. It must be the HTTPS URL of a Bitbucket repository.", @@ -798,10 +797,9 @@ impl GitBitbucketDriver { url: &str, _deep: bool, ) -> anyhow::Result<bool> { - if preg_match2( + if preg_match( php_regex!(r"#^https?://bitbucket\.org/([^/]+)/([^/]+?)(\.git|/?)?$#i"), url, - 0, ) .is_none() { diff --git a/crates/shirabe/src/repository/vcs/git_driver.rs b/crates/shirabe/src/repository/vcs/git_driver.rs index 62cca379..63598517 100644 --- a/crates/shirabe/src/repository/vcs/git_driver.rs +++ b/crates/shirabe/src/repository/vcs/git_driver.rs @@ -16,7 +16,7 @@ use chrono::{DateTime, FixedOffset, Utc}; use indexmap::IndexMap; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ - InvalidArgumentException, RuntimeException, dirname, is_dir, is_writable, preg_match2, + InvalidArgumentException, RuntimeException, dirname, is_dir, is_writable, preg_match, preg_replace, realpath, sys_get_temp_dir, }; use shirabe_php_shim::{PhpMixed, php_regex}; @@ -98,13 +98,7 @@ impl GitDriver { .into()); } - if preg_match2( - php_regex!(r"{^ssh://[^@]+@[^:]+:[^0-9]+}"), - &self.inner.url, - 0, - ) - .is_some() - { + if preg_match(php_regex!(r"{^ssh://[^@]+@[^:]+:[^0-9]+}"), &self.inner.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.", self.inner.url @@ -204,7 +198,7 @@ impl GitDriver { if !branches.contains(&"* master".to_string()) { for branch in &branches { if !branch.is_empty() - && let Some(caps) = preg_match2(php_regex!(r"{^\* +(\S+)}"), branch, 0) + && let Some(caps) = preg_match(php_regex!(r"{^\* +(\S+)}"), branch) && let Some(name) = caps.get(1) { self.root_identifier = Some(name.to_string()); @@ -314,10 +308,9 @@ impl GitDriver { ); for tag in self.inner.process.borrow().split_lines(&output) { if !tag.is_empty() - && let Some(caps) = preg_match2( + && let Some(caps) = preg_match( php_regex!(r"{^([a-f0-9]{40}) refs/tags/(\S+?)(\^\{\})?$}"), &tag, - 0, ) && let (Some(hash), Some(name)) = (caps.get(1), caps.get(2)) { @@ -350,11 +343,10 @@ impl GitDriver { ); for branch in self.inner.process.borrow().split_lines(&output) { if !branch.is_empty() - && preg_match2(php_regex!(r"{^ *[^/]+/HEAD }"), &branch, 0).is_none() - && let Some(caps) = preg_match2( + && preg_match(php_regex!(r"{^ *[^/]+/HEAD }"), &branch).is_none() + && let Some(caps) = preg_match( php_regex!(r"{^(?:\* )? *(\S+) *([a-f0-9]+)(?: .*)?$}"), &branch, - 0, ) && let (Some(name), Some(hash)) = (caps.get(1), caps.get(2)) && !name.starts_with('-') @@ -375,10 +367,9 @@ impl GitDriver { url: &str, deep: bool, ) -> anyhow::Result<bool> { - if preg_match2( + if preg_match( php_regex!(r"#(^git://|\.git/?$|git(?:olite)?@|//git\.|//github.com/)#i"), url, - 0, ) .is_some() { diff --git a/crates/shirabe/src/repository/vcs/github_driver.rs b/crates/shirabe/src/repository/vcs/github_driver.rs index e9c17d30..f310da3d 100644 --- a/crates/shirabe/src/repository/vcs/github_driver.rs +++ b/crates/shirabe/src/repository/vcs/github_driver.rs @@ -18,7 +18,7 @@ use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ InvalidArgumentException, PhpMixed, RuntimeException, array_diff, array_map, array_search_mixed, base64_decode, basename, empty, explode, extension_loaded, in_array_loose, - parse_url, php_regex, preg_match2, preg_replace, preg_split, strpos, strtolower, substr, trim, + parse_url, php_regex, preg_match, preg_replace, preg_split, strpos, strtolower, substr, trim, urlencode, }; @@ -70,12 +70,11 @@ impl GitHubDriver { } pub fn initialize(&mut self) -> anyhow::Result<()> { - let Some(match_) = preg_match2( + let Some(match_) = preg_match( php_regex!( r"#^(?:(?:https?|git)://([^/]+)/|git@([^:]+):/?)([^/]+)/([^/]+?)(?:\.git|/)?$#" ), &self.inner.url, - 0, ) else { return Err(InvalidArgumentException::new(format!( "The GitHub repository URL {} is invalid.", @@ -483,14 +482,14 @@ impl GitHubDriver { let mut key: Option<String> = None; for line in preg_split(php_regex!(r"{\r?\n}"), &funding) { let line = trim(&line, None); - if let Some(m) = preg_match2(php_regex!(r"{^(\w+)\s*:\s*(.+)$}"), &line, 0) { + if let Some(m) = preg_match(php_regex!(r"{^(\w+)\s*:\s*(.+)$}"), &line) { let g1 = m.get(1).unwrap_or_default().to_string(); let g2 = m.get(2).unwrap_or_default().to_string(); if g2 == "[" { key = Some(g1); continue; } - if let Some(m2) = preg_match2(php_regex!(r"{^\[(.*?)\](?:\s*#.*)?$}"), &g2, 0) { + if let Some(m2) = preg_match(php_regex!(r"{^\[(.*?)\](?:\s*#.*)?$}"), &g2) { let inner = m2.get(1).unwrap_or_default().to_string(); for item in array_map( |s: &String| trim(s, None), @@ -504,9 +503,7 @@ impl GitHubDriver { ); result.push(entry); } - } else if let Some(m2) = - preg_match2(php_regex!(r"{^([^#].*?)(?:\s+#.*)?$}"), &g2, 0) - { + } else if let Some(m2) = preg_match(php_regex!(r"{^([^#].*?)(?:\s+#.*)?$}"), &g2) { let mut entry = IndexMap::new(); entry.insert("type".to_string(), PhpMixed::String(g1.clone())); entry.insert( @@ -516,11 +513,11 @@ impl GitHubDriver { result.push(entry); } key = None; - } else if let Some(m) = preg_match2(php_regex!(r"{^(\w+)\s*:\s*#\s*$}"), &line, 0) { + } else if let Some(m) = preg_match(php_regex!(r"{^(\w+)\s*:\s*#\s*$}"), &line) { key = Some(m.get(1).unwrap_or_default().to_string()); } else if key.is_some() - && let Some(m) = preg_match2(php_regex!(r"{^-\s*(.+)(?:\s+#.*)?$}"), &line, 0) - .or_else(|| preg_match2(php_regex!(r"{^(.+),(?:\s*#.*)?$}"), &line, 0)) + && let Some(m) = preg_match(php_regex!(r"{^-\s*(.+)(?:\s+#.*)?$}"), &line) + .or_else(|| preg_match(php_regex!(r"{^(.+),(?:\s*#.*)?$}"), &line)) { let mut entry = IndexMap::new(); entry.insert( @@ -645,7 +642,7 @@ impl GitHubDriver { }; if bits.scheme.is_none() && bits.host.is_none() { - if preg_match2(php_regex!(r"{^[a-z0-9-]++\.[a-z]{2,3}$}"), &item_url, 0) + if preg_match(php_regex!(r"{^[a-z0-9-]++\.[a-z]{2,3}$}"), &item_url) .is_some() { result[key_idx].insert( @@ -911,12 +908,11 @@ impl GitHubDriver { url: &str, _deep: bool, ) -> anyhow::Result<bool> { - let Some(matches) = preg_match2( + let Some(matches) = preg_match( php_regex!( r"#^((?:https?|git)://([^/]+)/|git@([^:]+):/?)([^/]+)/([^/]+?)(?:\.git|/)?$#" ), url, - 0, ) else { return Ok(false); }; @@ -1253,7 +1249,7 @@ impl GitHubDriver { let links = explode(",", &header); for link in &links { - if let Some(m) = preg_match2(php_regex!(r#"{<(.+?)>; *rel="next"}"#), link, 0) { + if let Some(m) = preg_match(php_regex!(r#"{<(.+?)>; *rel="next"}"#), link) { return Some(m.get(1).unwrap_or_default().to_string()); } } diff --git a/crates/shirabe/src/repository/vcs/gitlab_driver.rs b/crates/shirabe/src/repository/vcs/gitlab_driver.rs index 6054d941..229d043b 100644 --- a/crates/shirabe/src/repository/vcs/gitlab_driver.rs +++ b/crates/shirabe/src/repository/vcs/gitlab_driver.rs @@ -19,7 +19,7 @@ use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ InvalidArgumentException, LogicException, PhpMixed, RuntimeException, array_search_mixed, array_shift, ctype_alnum, empty, explode, extension_loaded, implode, in_array_loose, is_array, - is_string, ord, php_regex, preg_match2, preg_replace, strpos, strtolower, + is_string, ord, php_regex, preg_match, preg_replace, strpos, strtolower, }; /// Driver for GitLab API, use the Git driver for local checkouts. @@ -80,7 +80,7 @@ impl GitLabDriver { /// /// SSH urls use https by default. Set "secure-http": false on the repository config to use http instead. pub fn initialize(&mut self) -> anyhow::Result<()> { - let Some(match_) = preg_match2(Self::URL_REGEX, &self.inner.url, 0) else { + let Some(match_) = preg_match(Self::URL_REGEX, &self.inner.url) else { return Err(InvalidArgumentException::new(format!( "The GitLab repository URL {} is invalid. It must be the HTTP URL of a GitLab project.", self.inner.url.clone(), @@ -382,7 +382,7 @@ impl GitLabDriver { // Convert the root identifier to a cacheable commit id let mut identifier = identifier.to_string(); - if preg_match2(php_regex!(r"{[a-f0-9]{40}}i"), &identifier, 0).is_none() { + if preg_match(php_regex!(r"{[a-f0-9]{40}}i"), &identifier).is_none() { let branches = self.get_branches()?; if let Some(sha) = branches.get(&identifier) { identifier = sha.clone(); @@ -926,7 +926,7 @@ impl GitLabDriver { url: &str, _deep: bool, ) -> anyhow::Result<bool> { - let Some(match_) = preg_match2(Self::URL_REGEX, url, 0) else { + let Some(match_) = preg_match(Self::URL_REGEX, url) else { return Ok(false); }; @@ -977,7 +977,7 @@ impl GitLabDriver { let links = explode(",", &header); for link in &links { - if let Some(match_) = preg_match2(php_regex!(r#"{<(.+?)>; *rel="next"}"#), link, 0) { + if let Some(match_) = preg_match(php_regex!(r#"{<(.+?)>; *rel="next"}"#), link) { return Some(match_.get(1).unwrap_or_default().to_string()); } } diff --git a/crates/shirabe/src/repository/vcs/hg_driver.rs b/crates/shirabe/src/repository/vcs/hg_driver.rs index ada1063e..977d6b97 100644 --- a/crates/shirabe/src/repository/vcs/hg_driver.rs +++ b/crates/shirabe/src/repository/vcs/hg_driver.rs @@ -13,7 +13,7 @@ use chrono::{DateTime, FixedOffset, Utc}; use indexmap::IndexMap; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ - PhpMixed, RuntimeException, dirname, is_dir, is_writable, php_regex, preg_match2, preg_replace, + PhpMixed, RuntimeException, dirname, is_dir, is_writable, php_regex, preg_match, preg_replace, }; #[derive(Debug)] @@ -234,7 +234,7 @@ impl HgDriver { ); for tag in self.inner.process.borrow().split_lines(&output) { if !tag.is_empty() - && let Some(m) = preg_match2(php_regex!(r"(^([^\s]+)\s+\d+:(.*)$)"), &tag, 0) + && let Some(m) = preg_match(php_regex!(r"(^([^\s]+)\s+\d+:(.*)$)"), &tag) { tags.insert( m.get(1).unwrap_or_default().to_string(), @@ -264,7 +264,7 @@ impl HgDriver { for branch in self.inner.process.borrow().split_lines(&output) { if !branch.is_empty() && let Some(m) = - preg_match2(php_regex!(r"(^([^\s]+)\s+\d+:([a-f0-9]+))"), &branch, 0) + preg_match(php_regex!(r"(^([^\s]+)\s+\d+:([a-f0-9]+))"), &branch) { let name = m.get(1).unwrap_or_default().to_string(); if !name.starts_with('-') { @@ -282,7 +282,7 @@ impl HgDriver { for branch in self.inner.process.borrow().split_lines(&output) { if !branch.is_empty() && let Some(m) = - preg_match2(php_regex!(r"(^(?:[\s*]*)([^\s]+)\s+\d+:(.*)$)"), &branch, 0) + preg_match(php_regex!(r"(^(?:[\s*]*)([^\s]+)\s+\d+:(.*)$)"), &branch) { let name = m.get(1).unwrap_or_default().to_string(); if !name.starts_with('-') { @@ -305,12 +305,11 @@ impl HgDriver { url: &str, deep: bool, ) -> anyhow::Result<bool> { - if preg_match2( + if preg_match( php_regex!( r"#(^(?:https?|ssh)://(?:[^@]+@)?bitbucket.org|https://(?:.*?)\.kilnhg.com)#i" ), url, - 0, ) .is_some() { diff --git a/crates/shirabe/src/repository/vcs/perforce_driver.rs b/crates/shirabe/src/repository/vcs/perforce_driver.rs index 50aed379..16dad1e9 100644 --- a/crates/shirabe/src/repository/vcs/perforce_driver.rs +++ b/crates/shirabe/src/repository/vcs/perforce_driver.rs @@ -9,9 +9,7 @@ use crate::util::PerforceInterface; use crate::util::ProcessExecutor; use crate::util::http::Response; use indexmap::IndexMap; -use shirabe_php_shim::{ - BadMethodCallException, PhpMixed, RuntimeException, php_regex, preg_match2, -}; +use shirabe_php_shim::{BadMethodCallException, PhpMixed, RuntimeException, php_regex, preg_match}; #[derive(Debug)] pub struct PerforceDriver { @@ -190,7 +188,7 @@ impl PerforceDriver { url: &str, deep: bool, ) -> anyhow::Result<bool> { - if deep || preg_match2(php_regex!(r"#\b(perforce|p4)\b#i"), url, 0).is_some() { + if deep || preg_match(php_regex!(r"#\b(perforce|p4)\b#i"), url).is_some() { return Ok(Perforce::check_server_exists( url, &mut ProcessExecutor::new(Some(io)), diff --git a/crates/shirabe/src/repository/vcs/svn_driver.rs b/crates/shirabe/src/repository/vcs/svn_driver.rs index 3398eb59..28239452 100644 --- a/crates/shirabe/src/repository/vcs/svn_driver.rs +++ b/crates/shirabe/src/repository/vcs/svn_driver.rs @@ -15,7 +15,7 @@ use chrono::{DateTime, FixedOffset, Utc}; use indexmap::IndexMap; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ - PhpMixed, RuntimeException, php_regex, preg_match2, preg_replace, stripos, strrpos, strtr, + PhpMixed, RuntimeException, php_regex, preg_match, preg_replace, stripos, strrpos, strtr, substr, trim, }; @@ -153,7 +153,7 @@ impl SvnDriver { } fn should_cache(&self, identifier: &str) -> bool { - self.inner.cache.is_some() && preg_match2(php_regex!(r"{@\d+$}"), identifier, 0).is_some() + self.inner.cache.is_some() && preg_match(php_regex!(r"{@\d+$}"), identifier).is_some() } pub fn get_composer_information( @@ -257,8 +257,7 @@ impl SvnDriver { ) -> anyhow::Result<Option<String>> { let identifier = format!("/{}/", trim(identifier, Some("/"))); - let (path, rev) = if let Some(m) = - preg_match2(php_regex!(r"{^(.+?)(@\d+)?/$}"), &identifier, 0) + let (path, rev) = if let Some(m) = preg_match(php_regex!(r"{^(.+?)(@\d+)?/$}"), &identifier) && let Some(rev) = m.get(2) { (m.get(1).unwrap_or_default().to_string(), rev.to_string()) @@ -291,8 +290,7 @@ impl SvnDriver { ) -> anyhow::Result<Option<DateTime<FixedOffset>>> { let identifier = format!("/{}/", trim(identifier, Some("/"))); - let (path, rev) = if let Some(m) = - preg_match2(php_regex!(r"{^(.+?)(@\d+)?/$}"), &identifier, 0) + let (path, rev) = if let Some(m) = preg_match(php_regex!(r"{^(.+?)(@\d+)?/$}"), &identifier) && let Some(rev) = m.get(2) { (m.get(1).unwrap_or_default().to_string(), rev.to_string()) @@ -306,7 +304,7 @@ impl SvnDriver { )?; for line in self.inner.process.borrow().split_lines(&output) { if !line.is_empty() - && let Some(m) = preg_match2(php_regex!(r"{^Last Changed Date: ([^(]+)}"), &line, 0) + && let Some(m) = preg_match(php_regex!(r"{^Last Changed Date: ([^(]+)}"), &line) { let date_str = m.get(1).unwrap_or_default().to_string(); return Ok(shirabe_php_shim::date_create::<Utc>(date_str.trim()) @@ -334,7 +332,7 @@ impl SvnDriver { let line = trim(&line, None); if !line.is_empty() && let Some(m) = - preg_match2(php_regex!(r"{^\s*(\S+).*?(\S+)\s*$}"), &line, 0) + preg_match(php_regex!(r"{^\s*(\S+).*?(\S+)\s*$}"), &line) { let rev: i64 = m.get(1).and_then(|s| s.parse().ok()).unwrap_or(0); let path = m.get(2).unwrap_or_default().to_string(); @@ -376,8 +374,7 @@ impl SvnDriver { for line in self.inner.process.borrow().split_lines(&output) { let line = trim(&line, None); if !line.is_empty() - && let Some(m) = - preg_match2(php_regex!(r"{^\s*(\S+).*?(\S+)\s*$}"), &line, 0) + && let Some(m) = preg_match(php_regex!(r"{^\s*(\S+).*?(\S+)\s*$}"), &line) { let rev: i64 = m.get(1).and_then(|s| s.parse().ok()).unwrap_or(0); let path = m.get(2).unwrap_or_default().to_string(); @@ -412,7 +409,7 @@ impl SvnDriver { let line = trim(&line, None); if !line.is_empty() && let Some(m) = - preg_match2(php_regex!(r"{^\s*(\S+).*?(\S+)\s*$}"), &line, 0) + preg_match(php_regex!(r"{^\s*(\S+).*?(\S+)\s*$}"), &line) { let rev: i64 = m.get(1).and_then(|s| s.parse().ok()).unwrap_or(0); let path = m.get(2).unwrap_or_default().to_string(); @@ -443,7 +440,7 @@ impl SvnDriver { deep: bool, ) -> anyhow::Result<bool> { let url = Self::normalize_url(url); - if preg_match2(php_regex!(r"#(^svn://|^svn\+ssh://|svn\.)#i"), &url, 0).is_some() { + if preg_match(php_regex!(r"#(^svn://|^svn\+ssh://|svn\.)#i"), &url).is_some() { return Ok(true); } diff --git a/crates/shirabe/src/repository/vcs/vcs_driver.rs b/crates/shirabe/src/repository/vcs/vcs_driver.rs index 1a5ee72e..439275f1 100644 --- a/crates/shirabe/src/repository/vcs/vcs_driver.rs +++ b/crates/shirabe/src/repository/vcs/vcs_driver.rs @@ -13,7 +13,7 @@ use crate::util::http::Response; use chrono::{DateTime, FixedOffset}; use indexmap::IndexMap; use shirabe_php_shim::Catch as _; -use shirabe_php_shim::{DATE_RFC3339, PhpMixed, extension_loaded, php_regex, preg_match2}; +use shirabe_php_shim::{DATE_RFC3339, PhpMixed, extension_loaded, php_regex, preg_match}; #[derive(Debug)] pub struct VcsDriverBase { @@ -56,8 +56,7 @@ impl VcsDriverBase { } pub fn should_cache(&self, identifier: &str) -> bool { - self.cache.is_some() - && preg_match2(php_regex!("{^[a-f0-9]{40}$}iD"), identifier, 0).is_some() + self.cache.is_some() && preg_match(php_regex!("{^[a-f0-9]{40}$}iD"), identifier).is_some() } pub fn get_scheme(&self) -> &str { @@ -202,8 +201,7 @@ pub trait VcsDriver: VcsDriverInterface { fn cache_mut(&mut self) -> Option<&mut Cache>; fn should_cache(&self, identifier: &str) -> bool { - self.cache().is_some() - && preg_match2(php_regex!("{^[a-f0-9]{40}$}iD"), identifier, 0).is_some() + self.cache().is_some() && preg_match(php_regex!("{^[a-f0-9]{40}$}iD"), identifier).is_some() } fn get_composer_information( diff --git a/crates/shirabe/src/repository/vcs_repository.rs b/crates/shirabe/src/repository/vcs_repository.rs index 33de3dfb..f22ab618 100644 --- a/crates/shirabe/src/repository/vcs_repository.rs +++ b/crates/shirabe/src/repository/vcs_repository.rs @@ -29,8 +29,8 @@ use crate::util::Url; use indexmap::IndexMap; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ - InvalidArgumentException, PhpClass, PhpMixed, php_regex, preg_match2, preg_replace, - str_replace, strpos, + InvalidArgumentException, PhpClass, PhpMixed, php_regex, preg_match, preg_replace, str_replace, + strpos, }; use shirabe_semver::constraint::SimpleConstraint; @@ -510,9 +510,7 @@ impl VcsRepository { // broken package, version doesn't match tag if version_normalized != parsed_tag { if is_very_verbose { - if preg_match2(php_regex!(r"{(^dev-|[.-]?dev$)}i"), &parsed_tag, 0) - .is_some() - { + if preg_match(php_regex!(r"{(^dev-|[.-]?dev$)}i"), &parsed_tag).is_some() { self.io.write_error(&format!( "<warning>Skipped tag {}, invalid tag name, tags can not use dev prefixes or suffixes</warning>", tag diff --git a/crates/shirabe/src/self_update/versions.rs b/crates/shirabe/src/self_update/versions.rs index 89028dc5..f5800a65 100644 --- a/crates/shirabe/src/self_update/versions.rs +++ b/crates/shirabe/src/self_update/versions.rs @@ -6,7 +6,7 @@ use crate::io::IOInterfaceImmutable; use crate::util::HttpDownloader; use indexmap::IndexMap; use shirabe_php_shim::{ - InvalidArgumentException, PHP_EOL, PhpMixed, UnexpectedValueException, php_regex, preg_match2, + InvalidArgumentException, PHP_EOL, PhpMixed, UnexpectedValueException, php_regex, preg_match, }; pub struct Versions { @@ -89,7 +89,7 @@ impl Versions { self.channel = Some(channel.clone()); // rewrite '2' and '1' channels to stable for future self-updates, but LTS ones like '2.2' remain pinned - let stored_channel = if preg_match2(php_regex!(r"{^\d+$}D"), &channel, 0).is_some() { + let stored_channel = if preg_match(php_regex!(r"{^\d+$}D"), &channel).is_some() { "stable".to_string() } else { channel 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, ) diff --git a/crates/shirabe/tests/all_functional_test.rs b/crates/shirabe/tests/all_functional_test.rs index 36137955..9879bca4 100644 --- a/crates/shirabe/tests/all_functional_test.rs +++ b/crates/shirabe/tests/all_functional_test.rs @@ -8,7 +8,7 @@ use indexmap::IndexMap; use serial_test::serial; use shirabe::util::filesystem::Filesystem; -use shirabe_php_shim::{PhpMixed, intval, php_regex, preg_match2, preg_split_delim_capture}; +use shirabe_php_shim::{PhpMixed, intval, php_regex, preg_match, preg_split_delim_capture}; use std::path::{Path, PathBuf}; /// ref: AllFunctionalTest's `$oldcwd` / `$testDir` instance state plus its `setUp`/`tearDown`. @@ -140,13 +140,13 @@ fn expect_matches(expected: &str, output: &str) { line += 1; } if eb[i] == b'%' { - let Some(m) = preg_match2(php_regex!("{%(.+?)%}"), &expected[i..], 0) else { + let Some(m) = preg_match(php_regex!("{%(.+?)%}"), &expected[i..]) else { panic!("Failed to match %...% in {}", &expected[i..]); }; let regex = m.get(1).map(str::to_string).unwrap(); let pattern = format!("{{{}}}", regex); - if let Some(m) = preg_match2(&pattern, &output[j..], 0) { + if let Some(m) = preg_match(&pattern, &output[j..]) { let full = m.get(0).map(str::to_string).unwrap(); i += regex.len() + 2; j += full.len(); @@ -221,13 +221,13 @@ fn run_integration(test_filename: &str) { expect_matches(expected, output); } if let Some(expect_regex) = test_data.get("EXPECT-REGEX") { - assert!(preg_match2(expect_regex, &clean_output(&raw_output), 0).is_some()); + assert!(preg_match(expect_regex, &clean_output(&raw_output)).is_some()); } if let Some(expect_regexes) = test_data.get("EXPECT-REGEXES") { let clean = clean_output(&raw_output); for regex in expect_regexes.split('\n') { assert!( - preg_match2(regex, &clean, 0).is_some(), + preg_match(regex, &clean).is_some(), "Output: {}", raw_output ); diff --git a/crates/shirabe/tests/common/io_mock.rs b/crates/shirabe/tests/common/io_mock.rs index 7aaa231a..a6a407a3 100644 --- a/crates/shirabe/tests/common/io_mock.rs +++ b/crates/shirabe/tests/common/io_mock.rs @@ -5,7 +5,7 @@ use shirabe::io::buffer_io::BufferIO; use shirabe::io::io_interface; use shirabe::io::{IOInterface, IOInterfaceImmutable, IOInterfaceMutable}; use shirabe::util::platform::Platform; -use shirabe_php_shim::{PHP_EOL, PhpMixed, php_regex, preg_match2, preg_quote, preg_split}; +use shirabe_php_shim::{PHP_EOL, PhpMixed, php_regex, preg_match, preg_quote, preg_split}; use shirabe_symfony_console::output::output_interface; use std::collections::VecDeque; @@ -166,7 +166,7 @@ impl IOMock { }; while let Some(line) = lines.pop_front() { - if preg_match2(&pattern, &line, 0).is_some() { + if preg_match(&pattern, &line).is_some() { continue 'expects; } diff --git a/crates/shirabe/tests/dependency_resolver/pool_builder_test.rs b/crates/shirabe/tests/dependency_resolver/pool_builder_test.rs index 27359fa3..e04e2ca9 100644 --- a/crates/shirabe/tests/dependency_resolver/pool_builder_test.rs +++ b/crates/shirabe/tests/dependency_resolver/pool_builder_test.rs @@ -19,7 +19,7 @@ use shirabe::repository::handle::{LockArrayRepositoryHandle, RepositoryInterface use shirabe::repository::lock_array_repository::LockArrayRepository; use shirabe::repository::repository_factory::RepositoryFactory; use shirabe::repository::repository_set::{RepositorySet, RootAliasInput}; -use shirabe_php_shim::{PhpMixed, php_regex, preg_match2, preg_split_delim_capture}; +use shirabe_php_shim::{PhpMixed, php_regex, preg_match, preg_split_delim_capture}; use std::path::PathBuf; /// Maps the PHP `$loadPackage` closure: pops the optional `id` from the data, loads the @@ -137,7 +137,7 @@ fn get_integration_tests(fixtures_dir: &std::path::Path) -> IndexMap<String, Int for file in files { let file = file.to_str().unwrap().to_string(); - if preg_match2(php_regex!(r"/\.test$/"), &file, 0).is_none() { + if preg_match(php_regex!(r"/\.test$/"), &file).is_none() { continue; } diff --git a/crates/shirabe/tests/dependency_resolver/pool_optimizer_test.rs b/crates/shirabe/tests/dependency_resolver/pool_optimizer_test.rs index cac8189d..e40d5257 100644 --- a/crates/shirabe/tests/dependency_resolver/pool_optimizer_test.rs +++ b/crates/shirabe/tests/dependency_resolver/pool_optimizer_test.rs @@ -11,7 +11,7 @@ use shirabe::package::loader::{ArrayLoader, LoaderInterface}; use shirabe::package::version::version_parser::VersionParser; use shirabe::repository::handle::LockArrayRepositoryHandle; use shirabe::repository::lock_array_repository::LockArrayRepository; -use shirabe_php_shim::{PhpMixed, php_regex, preg_match2, preg_split_delim_capture}; +use shirabe_php_shim::{PhpMixed, php_regex, preg_match, preg_split_delim_capture}; use std::path::PathBuf; fn load_package(package_data: &PhpMixed) -> BasePackageHandle { @@ -140,7 +140,7 @@ fn provide_integration_tests() -> IndexMap< for file in files { let file = file.to_str().unwrap().to_string(); - if preg_match2(php_regex!(r"/\.test$/"), &file, 0).is_none() { + if preg_match(php_regex!(r"/\.test$/"), &file).is_none() { continue; } diff --git a/crates/shirabe/tests/installer_test.rs b/crates/shirabe/tests/installer_test.rs index 5503824e..606baacc 100644 --- a/crates/shirabe/tests/installer_test.rs +++ b/crates/shirabe/tests/installer_test.rs @@ -42,7 +42,7 @@ use shirabe::util::r#loop::Loop; use shirabe::util::platform::Platform; use shirabe::util::process_executor::ProcessExecutor; use shirabe_class_map_generator::class_map::ClassMap; -use shirabe_php_shim::{PhpMixed, php_regex, preg_match2, preg_replace, preg_split_delim_capture}; +use shirabe_php_shim::{PhpMixed, php_regex, preg_match, preg_replace, preg_split_delim_capture}; use shirabe_semver::VersionParser; use shirabe_semver::constraint::AnyConstraint; use shirabe_symfony_console::command::Command as SymfonyCommand; @@ -691,7 +691,7 @@ fn load_integration_tests(path: &str) -> Vec<IntegrationCase> { return; } if let Some(url) = repo.get("url").and_then(|u| u.as_str()) - && preg_match2(php_regex!(r"{^file://[^/]}"), url, 0).is_some() + && preg_match(php_regex!(r"{^file://[^/]}"), url).is_some() { let new_url = format!("file://{}/{}", fixtures_str, &url[7..]); repo["url"] = serde_json::Value::String(new_url); @@ -1137,7 +1137,7 @@ fn do_test_integration(case: &IntegrationCase, expect_output: Option<&str>) { .unwrap(); assert!( - preg_match2(r"{^(install|update)\b}", &case.run, 0).is_some(), + preg_match(r"{^(install|update)\b}", &case.run).is_some(), "The run command only supports install and update" ); |
