aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/util
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-17 04:55:59 +0900
committernsfisis <nsfisis@gmail.com>2026-08-17 04:55:59 +0900
commitea39e2301824435d45db88f95867dbe692aaf21e (patch)
treebb4a1210f34eb63b1b4965e7e5fc556ca87271ae /crates/shirabe/src/util
parentbc79875f9a0cbacce94722fede76228b06486269 (diff)
downloadphp-shirabe-ea39e2301824435d45db88f95867dbe692aaf21e.tar.gz
php-shirabe-ea39e2301824435d45db88f95867dbe692aaf21e.tar.zst
php-shirabe-ea39e2301824435d45db88f95867dbe692aaf21e.zip
fix(platform): expand the %VAR% form in expand_path()
The alternation that stands in for the original conditional subpattern reports the branch it did not take as an empty string, so `dvar` was always present and won over `pvar`, leaving %VAR% unexpanded. `\w+` cannot capture an empty string, so an empty branch means it did not participate. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/util')
-rw-r--r--crates/shirabe/src/util/platform.rs4
1 files changed, 3 insertions, 1 deletions
diff --git a/crates/shirabe/src/util/platform.rs b/crates/shirabe/src/util/platform.rs
index f45294d5..4336de53 100644
--- a/crates/shirabe/src/util/platform.rs
+++ b/crates/shirabe/src/util/platform.rs
@@ -95,12 +95,14 @@ impl Platform {
// Regex pattern compatibility:
// The original pattern uses a conditional subpattern to make the trailing `%` required
// only for the `%VAR%` form. The Rust regex crate does not support conditionals, so the
- // two forms are written as an explicit alternation: `$VAR` or `%VAR%`.
+ // two forms are written as an explicit alternation: `$VAR` or `%VAR%`. The branch that did
+ // not participate is reported as an empty string, which `\w+` can never capture.
Preg::replace_callback(
php_regex!(r"#^(?:\$(?P<dvar>\w+)|%(?P<pvar>\w+)%)(?P<path>.*)#"),
|matches: &indexmap::IndexMap<CaptureKey, String>| -> String {
let var = matches
.get(&CaptureKey::ByName("dvar".to_string()))
+ .filter(|dvar| !dvar.is_empty())
.or_else(|| matches.get(&CaptureKey::ByName("pvar".to_string())))
.map(|s| s.as_str())
.unwrap_or("");