summaryrefslogtreecommitdiff
path: root/src/rebar_utils.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/rebar_utils.erl')
-rw-r--r--src/rebar_utils.erl18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl
index 84567ba..88c0c25 100644
--- a/src/rebar_utils.erl
+++ b/src/rebar_utils.erl
@@ -186,12 +186,18 @@ expand_code_path() ->
%% The end of form $FOO is delimited with whitespace or eol
%%
expand_env_variable(InStr, VarName, RawVarValue) ->
- ReOpts = [global, {return, list}],
- VarValue = re:replace(RawVarValue, "\\\\", "\\\\\\\\", ReOpts),
- R1 = re:replace(InStr, "\\\$" ++ VarName ++ "\\s", VarValue ++ " ",
- [global]),
- R2 = re:replace(R1, "\\\$" ++ VarName ++ "\$", VarValue),
- re:replace(R2, "\\\${" ++ VarName ++ "}", VarValue, ReOpts).
+ case string:chr(InStr, $$) of
+ 0 ->
+ %% No variables to expand
+ InStr;
+ _ ->
+ ReOpts = [global, {return, list}],
+ VarValue = re:replace(RawVarValue, "\\\\", "\\\\\\\\", [global]),
+ %% Use a regex to match/replace:
+ %% $FOO\s | ${FOO} | $FOO eol
+ RegEx = io_lib:format("\\\$(~s(\\s|$)|{~s})", [VarName, VarName]),
+ re:replace(InStr, RegEx, VarValue ++ "\\2", ReOpts)
+ end.
%% ====================================================================