erlware / relx

Sane, simple release creation for Erlang

Home Page:http://erlware.github.io/relx

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Replace of OS Variables enters endless loop if OS variable contains an ampersand

matthias-schoeneich opened this issue · comments

Hi,

i just noticed, that if the os variable contains an & ampersand character, the replacement of os variables enters and endless loop.

example:

export my_os_var="ab&cd"

sys.config.src snippet

...
   {[var_to_be_set,"${my_os_var}"]}
...

If i read this correctly, the following happens:

  • awk finds my_os_var from .src file in extended_bin in line 433
  • fetches the os variable into awk variable e in line 437
  • and tries to replace the string ${my_os_var} by the value of e: ab&cd
  • so that we should get the line {[var_to_be_set,"ab&cd"]}
  • however the ampersand character & in the replacement has a special meaning: "If the special character ‘&’ appears in replacement, it stands for the precise substring that was matched by regexp."
  • so we actually get {[var_to_be_set,"ab${my_os_var}cd"]}
  • which again matches in line 433, so we get {[var_to_be_set,"abab${my_os_var}cdcd"]}
  • ...
  • until we finally die

I am no awk expert, but replacing the literal character & in variable e with an escaped one like this

gsub("&","\\\\\\&",e)

at least for me would solve this problem.

Thank you
Matthias

Thanks for reporting. I'm not sure of the proper solution either but the substitution may be the best way to go forward, at least for the time being. Could you send a PR?

@ferd is the resident awk expert.