diff --git a/source/dub/project.d b/source/dub/project.d index d01fe41..9689f85 100644 --- a/source/dub/project.d +++ b/source/dub/project.d @@ -1185,8 +1185,10 @@ { import std.regex : regex, replaceAll; - auto varRE = regex(`\$([\w_]+)|\$\{([\w_]+)\}`); - var = var.replaceAll!(m => getVariable(m[1].length ? m[1] : m[2], project, pack, gsettings))(varRE); + auto varRE = regex(`\$([\w_]+)|\$\{([\w_]+)\}|(\$\$[\w_]+|\$\$\{[\w_]+\})`); + var = var.replaceAll!( + m => m[3].length ? m[3][1..$] : (getVariable(m[1].length ? m[1] : m[2], project, pack, gsettings)) + )(varRE); if (is_path) { auto p = NativePath(var); if (!p.absolute) { @@ -1310,6 +1312,8 @@ assert(processVars("Hello $PACKAGE_DIR"~dirSeparator~"foobar", proj, pack, gsettings, !isPath) == "Hello "~(pack.path ~ "foobar").toNativeString); // test with isPath assert(processVars("local", proj, pack, gsettings, isPath) == (pack.path ~ "local").toNativeString); + assert(processVars("foo/$$ESCAPED", proj, pack, gsettings, isPath) == (pack.path ~ "foo/$ESCAPED").toNativeString); + assert(processVars("$$ESCAPED", proj, pack, gsettings, !isPath) == "$ESCAPED"); // test other env variables import std.process : environment; environment["MY_ENV_VAR"] = "blablabla"; @@ -1317,6 +1321,7 @@ assert(processVars("${MY_ENV_VAR}suffix", proj, pack, gsettings, !isPath) == "blablablasuffix"); assert(processVars("$MY_ENV_VAR-suffix", proj, pack, gsettings, !isPath) == "blablabla-suffix"); assert(processVars("$MY_ENV_VAR:suffix", proj, pack, gsettings, !isPath) == "blablabla:suffix"); + assert(processVars("$MY_ENV_VAR$MY_ENV_VAR", proj, pack, gsettings, !isPath) == "blablablablablabla"); environment.remove("MY_ENV_VAR"); } diff --git a/test/issue1551-var-escaping/dub.json b/test/issue1551-var-escaping/dub.json new file mode 100644 index 0000000..f24ca66 --- /dev/null +++ b/test/issue1551-var-escaping/dub.json @@ -0,0 +1,7 @@ +{ + "name": "issue1551-var-escaping", + "preGenerateCommands": [ + "echo $${DUB_PACKAGE_DIR}", + "echo $$DUB_PACKAGE_DIR" + ] +} diff --git a/test/issue1551-var-escaping/source/app.d b/test/issue1551-var-escaping/source/app.d new file mode 100644 index 0000000..c3eec7f --- /dev/null +++ b/test/issue1551-var-escaping/source/app.d @@ -0,0 +1,6 @@ +import std.stdio; + +void main() +{ + writeln("Edit source/app.d to start your project."); +}