aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/package/version/version_bumper.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-17 03:09:04 +0900
committernsfisis <nsfisis@gmail.com>2026-08-17 03:09:04 +0900
commit8b57e90f5c563bbc1a6060d9f5e94b5d3cd91324 (patch)
treea8052aebf264e3cf31c25e2bc5cb612dadde485b /crates/shirabe/src/package/version/version_bumper.rs
parentfcc6ee5a13cd2e2b27fff66dcfc7e9e1f062a653 (diff)
downloadphp-shirabe-8b57e90f5c563bbc1a6060d9f5e94b5d3cd91324.tar.gz
php-shirabe-8b57e90f5c563bbc1a6060d9f5e94b5d3cd91324.tar.zst
php-shirabe-8b57e90f5c563bbc1a6060d9f5e94b5d3cd91324.zip
fix(pcre): preserve unmatched groups in Preg::match_all*()
PHP's Preg::matchAll() and matchAllWithOffsets() always set PREG_UNMATCHED_AS_NULL, so a non-participating group is `null` and its offset is -1. The Rust wrappers collapsed those to "" and 0, so callers could not tell a group that did not participate from one that matched an empty string at offset 0, and the offset value matched no PHP mode at all. Hand the shim's representation through unchanged and let each caller mirror what the PHP original does with it: `isset()` and `(string)` casts stay lenient, while `assert(is_string(...))` and the *StrictGroups() variants become `expect()`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/package/version/version_bumper.rs')
-rw-r--r--crates/shirabe/src/package/version/version_bumper.rs9
1 files changed, 6 insertions, 3 deletions
diff --git a/crates/shirabe/src/package/version/version_bumper.rs b/crates/shirabe/src/package/version/version_bumper.rs
index fcdbf246..83df211a 100644
--- a/crates/shirabe/src/package/version/version_bumper.rs
+++ b/crates/shirabe/src/package/version/version_bumper.rs
@@ -78,7 +78,7 @@ impl VersionBumper {
major = major
);
- let mut matches: IndexMap<CaptureKey, Vec<(String, usize)>> = IndexMap::new();
+ let mut matches: IndexMap<CaptureKey, Vec<(Option<String>, i64)>> = IndexMap::new();
if Preg::is_match_all_with_offsets3(&pattern, &pretty_constraint, Some(&mut matches)) {
let mut modified = pretty_constraint.clone();
let constraint_matches = matches
@@ -86,8 +86,11 @@ impl VersionBumper {
.cloned()
.unwrap_or_default();
for match_ in constraint_matches.iter().rev() {
- let match_str = &match_.0;
- let match_offset = match_.1 as i64;
+ let match_str = match_
+ .0
+ .as_deref()
+ .expect("the `constraint` group participates whenever the pattern matches");
+ let match_offset = match_.1;
let suffix = if match_str.matches('.').count() == 2
&& version_without_suffix.matches('.').count() == 1
{