diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-14 13:02:59 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-14 13:02:59 +0900 |
| commit | cfd2a4488797ddaabd0087aa0021b26892663ffb (patch) | |
| tree | ed2c030dded78355e0721d5458c2c6b12a3c2f2c /crates/shirabe-semver | |
| parent | c1070afe69f53b621adea232527080d2c922e1a9 (diff) | |
| download | php-shirabe-cfd2a4488797ddaabd0087aa0021b26892663ffb.tar.gz php-shirabe-cfd2a4488797ddaabd0087aa0021b26892663ffb.tar.zst php-shirabe-cfd2a4488797ddaabd0087aa0021b26892663ffb.zip | |
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) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-semver')
| -rw-r--r-- | crates/shirabe-semver/src/version_parser.rs | 11 |
1 files changed, 4 insertions, 7 deletions
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<AnyConstraint> { 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<AnyConstraint> = Vec::new(); @@ -306,8 +304,7 @@ impl VersionParser { let and_constraints = php::preg_split( "{(?<!^|as|[=>< ,]) *(?<!-)[, ](?!-) *(?!,|as|$)}", or_constraint, - ) - .ok_or_else(|| anyhow::anyhow!("Failed to preg_split string: {}", or_constraint))?; + ); let constraint_objects: Vec<AnyConstraint> = if and_constraints.len() > 1 { let mut objs: Vec<AnyConstraint> = Vec::new(); |
