From cfd2a4488797ddaabd0087aa0021b26892663ffb Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 14 Jun 2026 13:02:59 +0900 Subject: refactor(pcre): treat regex compile failure as fatal in shim The preg_* shim helpers wrapped their results in Option/Result solely to signal a regex that failed to compile. Composer never feeds a pattern that fails at runtime, so such a failure is a programming error: panic instead and drop the Option/Result wrappers, updating all callers. preg_replace_callback keeps its Result return type since the callback itself is fallible. preg_match_groups is removed in favor of preg_match at its sole call site. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/shirabe-semver/src/version_parser.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'crates/shirabe-semver') diff --git a/crates/shirabe-semver/src/version_parser.rs b/crates/shirabe-semver/src/version_parser.rs index bbd359e..bb4656c 100644 --- a/crates/shirabe-semver/src/version_parser.rs +++ b/crates/shirabe-semver/src/version_parser.rs @@ -25,7 +25,7 @@ pub struct VersionParser; impl VersionParser { pub fn parse_stability(version: &str) -> String { - let version = php::preg_replace("{#.+$}", "", version).unwrap_or_default(); + let version = php::preg_replace("{#.+$}", "", version); if version.starts_with("dev-") || version.ends_with("-dev") { return "dev".to_string(); @@ -143,8 +143,7 @@ impl VersionParser { MODIFIER_REGEX ); if php::preg_match(&datetime_pattern, &version, &mut matches) > 0 { - version = php::preg_replace("{\\D}", ".", matches[1].as_deref().unwrap_or("")) - .unwrap_or_default(); + version = php::preg_replace("{\\D}", ".", matches[1].as_deref().unwrap_or("")); index = Some(2); } } @@ -297,8 +296,7 @@ impl VersionParser { pub fn parse_constraints(&self, constraints: &str) -> anyhow::Result { let pretty_constraint = constraints.to_string(); - let or_constraints = php::preg_split("{\\s*\\|\\|?\\s*}", &php::trim(constraints, None)) - .ok_or_else(|| anyhow::anyhow!("Failed to preg_split string: {}", constraints))?; + let or_constraints = php::preg_split("{\\s*\\|\\|?\\s*}", &php::trim(constraints, None)); let mut or_groups: Vec = Vec::new(); @@ -306,8 +304,7 @@ impl VersionParser { let and_constraints = php::preg_split( "{(?< ,]) *(? = if and_constraints.len() > 1 { let mut objs: Vec = Vec::new(); -- cgit v1.3.1