Skip to content

Commit

Permalink
Merge pull request #889 from matthias-schoeneich/888-ampersand_in_os_…
Browse files Browse the repository at this point in the history
…variables

replace literal ampersand character in os variable by escaped version…
  • Loading branch information
ferd authored Nov 8, 2021
2 parents 5587173 + d7ee9d1 commit a146bee
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions priv/templates/extended_bin
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ replace_os_vars() {
slen=split(var,arr,":-")
v=arr[1]
e=ENVIRON[v]
gsub("&","\\\\\\&",e)
if(slen > 1 && e=="") {
i=index(var, ":-"arr[2])
def=substr(var,i+2)
Expand Down
3 changes: 2 additions & 1 deletion shelltests/replace_src_vars_tests/config/sys.config.src
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
{var5, "${VAR5}"},
{var6, "${VAR6:-test6:-6}"},
{var7, "${VAR7:-test7:-7:-7}"},
{var8, ${VAR8:-888}}]}].
{var8, ${VAR8:-888}},
{var9, "${VAR9}"}]}].
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ $ rebar3 release
> / Release successfully assembled: /
>= 0

$ RELX_OUT_FILE_PATH=/tmp NODENAME=node1 COOKIE=cookie1 VAR1=101 VAR2=201:-test2-2 VAR3=VA:-test3-2 VAR4=VAR4:-test4-2 VAR5=test5-2 VAR6=test6:-6-2 VAR7=test7:-7:-7-2 ./_build/default/rel/replace_os_vars_tests/bin/replace_os_vars_tests daemon
$ RELX_OUT_FILE_PATH=/tmp NODENAME=node1 COOKIE=cookie1 VAR1=101 VAR2=201:-test2-2 VAR3=VA:-test3-2 VAR4=VAR4:-test4-2 VAR5=test5-2 VAR6=test6:-6-2 VAR7=test7:-7:-7-2 VAR9="ab&cd" ./_build/default/rel/replace_os_vars_tests/bin/replace_os_vars_tests daemon
>= 0

$ sleep 1
Expand Down Expand Up @@ -59,6 +59,11 @@ $ NODENAME=node1 COOKIE=cookie1 ./_build/default/rel/replace_os_vars_tests/bin/r
888
>= 0

$ NODENAME=node1 COOKIE=cookie1 ./_build/default/rel/replace_os_vars_tests/bin/replace_os_vars_tests eval '{ok, [$a,$b,$&,$c,$d] = V} = application:get_env(replace_os_vars_tests, var9), V.'
>
"ab&cd"
>= 0

$ NODENAME=node1 COOKIE=cookie1 ./_build/default/rel/replace_os_vars_tests/bin/replace_os_vars_tests eval '[Node,_] = re:split(atom_to_list(node()), "@"),binary_to_list(Node).'
>
"node1"
Expand Down

0 comments on commit a146bee

Please sign in to comment.