aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--crates/shirabe/src/util/platform.rs4
-rw-r--r--crates/shirabe/tests/util/platform_test.rs3
2 files changed, 3 insertions, 4 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("");
diff --git a/crates/shirabe/tests/util/platform_test.rs b/crates/shirabe/tests/util/platform_test.rs
index 6c941ab2..be2764fe 100644
--- a/crates/shirabe/tests/util/platform_test.rs
+++ b/crates/shirabe/tests/util/platform_test.rs
@@ -4,9 +4,6 @@ use shirabe::util::platform::Platform;
use shirabe_php_shim::defined;
#[test]
-#[ignore = "Preg::replace_callback doesn't set PREG_UNMATCHED_AS_NULL, so the non-participating \
-alternation branch (dvar) is captured as an empty string instead of absent; Platform::expand_path's \
-matches.get(dvar).or_else(pvar) then picks the empty dvar over pvar for the %VAR% form"]
fn test_expand_path() {
Platform::put_env("TESTENV", "/home/test");
assert_eq!(