Skip to content

Commit d1606ef

Browse files
committed
Improve regex matching for env var substitutions
Also ensures match is left-anchored.
1 parent 7676fec commit d1606ef

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

apps/rebar/src/rebar_file_utils.erl

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,23 +160,19 @@ replace_env_vars([Char|Str]) ->
160160
[Char | replace_env_vars(Str)].
161161

162162
until_var_end(Str) ->
163-
case re:run(Str, "([a-zA-Z_]+[a-zA-Z0-9_]*)(:-[^}]*)?}", [{capture, [1,2], list}]) of
163+
case re:run(Str, "^([a-zA-Z_]+[a-zA-Z0-9_]*)(:-([^}]*))?}", [{capture, [1,3], list}]) of
164164
nomatch ->
165165
error;
166166
{match, [Name,Default]} ->
167-
%% the Default part will include the ":-" prefix if present
167+
%% the Default part will be "" if not present
168168
Rest = lists:nthtail(length(Name) + length(Default) + 1, Str),
169169
{ok, Name, Default, Rest}
170170
end.
171171

172172
replace_varname(Var, Default) ->
173173
%% os:getenv(Var, "") is only available in OTP-18.0
174174
case os:getenv(Var) of
175-
false ->
176-
case Default of
177-
":-" ++ Val -> Val;
178-
"" -> ""
179-
end;
175+
false -> Default;
180176
Val -> Val
181177
end.
182178

0 commit comments

Comments
 (0)