From e093b2be1c333e67c96aebb0a5291bea9ae3d6db Mon Sep 17 00:00:00 2001 From: nsfisis Date: Tue, 18 Aug 2026 01:57:02 +0900 Subject: refactor(preg): drop the offset argument from preg_match Every call site but one passed offset 0. The remaining one, the UTF-8 chunking loop in Application, slices the subject instead: its pattern has no anchor or lookaround, so matching a suffix is equivalent to starting the search at that offset. Co-Authored-By: Claude Opus 5 (1M context) --- crates/shirabe/src/command/package_discovery_trait.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'crates/shirabe/src/command/package_discovery_trait.rs') 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[\S/]+)(?:\s+(?P\S+))?\s*$}"), &selection, - 0, ) { if let Some(v) = m.name("version").map(str::to_string) { // parsing `acme/example ~2.3` -- cgit v1.3.1-4-g156e