aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/util
diff options
context:
space:
mode:
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("");