From 5e31fa33c3b5cf726a57a063b8e7a070869250fe Mon Sep 17 00:00:00 2001 From: nsfisis Date: Tue, 19 May 2026 21:46:01 +0900 Subject: fix(compile): fix more random compile errors Co-Authored-By: Claude Opus 4.7 (1M context) --- crates/shirabe/src/platform/version.rs | 84 +++++++++++++++++++++++++++------- 1 file changed, 68 insertions(+), 16 deletions(-) (limited to 'crates/shirabe/src/platform/version.rs') diff --git a/crates/shirabe/src/platform/version.rs b/crates/shirabe/src/platform/version.rs index a9566ee..2071d2a 100644 --- a/crates/shirabe/src/platform/version.rs +++ b/crates/shirabe/src/platform/version.rs @@ -1,6 +1,7 @@ //! ref: composer/src/Composer/Platform/Version.php -use shirabe_external_packages::composer::pcre::preg::Preg; +use indexmap::IndexMap; +use shirabe_external_packages::composer::pcre::preg::{CaptureKey, Preg}; use shirabe_php_shim::version_compare; pub struct Version; @@ -9,51 +10,102 @@ impl Version { pub fn parse_openssl(openssl_version: &str, is_fips: &mut bool) -> Option { *is_fips = false; - let matches = Preg::match_strict_groups( + let mut matches: IndexMap = IndexMap::new(); + if !Preg::match_strict_groups3( r"^(?P[0-9.]+)(?P[a-z]{0,2})(?P(?:-?(?:dev|pre|alpha|beta|rc|fips)[\d]*)*)(?:-\w+)?(?: \(.+?\))?$", openssl_version, - )?; + Some(&mut matches), + ) + .unwrap_or(false) + { + return None; + } + + let version = matches + .get(&CaptureKey::ByName("version".to_string())) + .cloned() + .unwrap_or_default(); + let patch_str = matches + .get(&CaptureKey::ByName("patch".to_string())) + .cloned() + .unwrap_or_default(); + let suffix_str = matches + .get(&CaptureKey::ByName("suffix".to_string())) + .cloned() + .unwrap_or_default(); - let patch = if version_compare(&matches["version"], "3.0.0", "<") { + let patch = if version_compare(&version, "3.0.0", "<") { format!( ".{}", - Self::convert_alpha_version_to_int_version(&matches["patch"]) + Self::convert_alpha_version_to_int_version(&patch_str) ) } else { String::new() }; - *is_fips = matches["suffix"].contains("fips"); - let suffix = format!("-{}", matches["suffix"].trim_start_matches('-')) + *is_fips = suffix_str.contains("fips"); + let suffix = format!("-{}", suffix_str.trim_start_matches('-')) .replace("-fips", "") .replace("-pre", "-alpha"); Some( - format!("{}{}{}", matches["version"], patch, suffix) + format!("{}{}{}", version, patch, suffix) .trim_end_matches('-') .to_string(), ) } pub fn parse_libjpeg(libjpeg_version: &str) -> Option { - let matches = - Preg::match_strict_groups(r"^(?P\d+)(?P[a-z]*)$", libjpeg_version)?; + let mut matches: IndexMap = IndexMap::new(); + if !Preg::match_strict_groups3( + r"^(?P\d+)(?P[a-z]*)$", + libjpeg_version, + Some(&mut matches), + ) + .unwrap_or(false) + { + return None; + } + let major = matches + .get(&CaptureKey::ByName("major".to_string())) + .cloned() + .unwrap_or_default(); + let minor = matches + .get(&CaptureKey::ByName("minor".to_string())) + .cloned() + .unwrap_or_default(); Some(format!( "{}.{}", - matches["major"], - Self::convert_alpha_version_to_int_version(&matches["minor"]) + major, + Self::convert_alpha_version_to_int_version(&minor) )) } pub fn parse_zoneinfo_version(zoneinfo_version: &str) -> Option { - let matches = - Preg::match_strict_groups(r"^(?P\d{4})(?P[a-z]*)$", zoneinfo_version)?; + let mut matches: IndexMap = IndexMap::new(); + if !Preg::match_strict_groups3( + r"^(?P\d{4})(?P[a-z]*)$", + zoneinfo_version, + Some(&mut matches), + ) + .unwrap_or(false) + { + return None; + } + let year = matches + .get(&CaptureKey::ByName("year".to_string())) + .cloned() + .unwrap_or_default(); + let revision = matches + .get(&CaptureKey::ByName("revision".to_string())) + .cloned() + .unwrap_or_default(); Some(format!( "{}.{}", - matches["year"], - Self::convert_alpha_version_to_int_version(&matches["revision"]) + year, + Self::convert_alpha_version_to_int_version(&revision) )) } -- cgit v1.3.1