From 8b57e90f5c563bbc1a6060d9f5e94b5d3cd91324 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 17 Aug 2026 03:09:04 +0900 Subject: 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) --- crates/shirabe/src/command/init_command.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'crates/shirabe/src/command') diff --git a/crates/shirabe/src/command/init_command.rs b/crates/shirabe/src/command/init_command.rs index c348fa6f..1ca3e428 100644 --- a/crates/shirabe/src/command/init_command.rs +++ b/crates/shirabe/src/command/init_command.rs @@ -175,17 +175,20 @@ impl InitCommand { ) == 0 { *self.git_config.borrow_mut() = Some(IndexMap::new()); - let mut m: IndexMap> = IndexMap::new(); + let mut m: IndexMap>> = IndexMap::new(); if Preg::is_match_all3(php_regex!(r"{^([^=]+)=(.*)$}m"), &output, Some(&mut m)) { - let keys: Vec = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(); - let values: Vec = + let keys: Vec> = + m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(); + let values: Vec> = m.get(&CaptureKey::ByIndex(2)).cloned().unwrap_or_default(); for (key, value) in keys.iter().zip(values.iter()) { - self.git_config - .borrow_mut() - .as_mut() - .unwrap() - .insert(key.clone(), value.clone()); + self.git_config.borrow_mut().as_mut().unwrap().insert( + key.clone() + .expect("group 1 participates whenever the pattern matches"), + value + .clone() + .expect("group 2 participates whenever the pattern matches"), + ); } } -- cgit v1.3.1-4-g156e