In elixir.bat some argument values are not properly quoted
E14 opened this issue · comments
Elixir and Erlang/OTP versions
Erlang/OTP 26 [erts-14.2.4] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit:ns]
Elixir 1.15.7 (compiled with Erlang/OTP 26)
Operating system
Windows 11
Current behavior
When passing CLI parameter -pa
with an argument that contains spaces, the elixir startup batch file will strip quotes and cmd.exe
will fail with an error message. This message can vary depending on how the path is constructed, for example here is the most simple reproducer I could think of
C:\>"c:\Program Files\Elixir\bin\elixir.bat" "-pa" "c:/Program files" -e "IO.puts('Success!')"
No file named files
This very likely applies to other parameters as well, like -r
, -pa
, -pr
, -pz
, as I understand all of those take a path value, but I don't know the semantics
Here's the code in question:
Lines 132 to 135 in 6f84158
Here's a diff/patch of the changes I made that resolved my immediate issue (but I'm not certain it won't produce other issues, quoting in CMD is weird):
--- a/elixir.prev.bat
+++ b/elixir.bat
@@ -129,10 +129,10 @@ if ""==!par:--rpc-eval=! (
goto startloop
)
rem ******* ELIXIR PARAMETERS **********************
-if ""==!par:-r=! (set "parsElixir=!parsElixir! -r %~1" && shift && goto startloop)
-if ""==!par:-pr=! (set "parsElixir=!parsElixir! -pr %~1" && shift && goto startloop)
-if ""==!par:-pa=! (set "parsElixir=!parsElixir! -pa %~1" && shift && goto startloop)
-if ""==!par:-pz=! (set "parsElixir=!parsElixir! -pz %~1" && shift && goto startloop)
+if ""==!par:-r=! (set "parsElixir=!parsElixir! -r "%~1"" && shift && goto startloop)
+if ""==!par:-pr=! (set "parsElixir=!parsElixir! -pr "%~1"" && shift && goto startloop)
+if ""==!par:-pa=! (set "parsElixir=!parsElixir! -pa "%~1"" && shift && goto startloop)
+if ""==!par:-pz=! (set "parsElixir=!parsElixir! -pz "%~1"" && shift && goto startloop)
if ""==!par:-v=! (set "parsElixir=!parsElixir! -v" && goto startloop)
if ""==!par:--version=! (set "parsElixir=!parsElixir! --version" && goto startloop)
if ""==!par:--no-halt=! (set "parsElixir=!parsElixir! --no-halt" && goto startloop)
So the %~1
removes surrounding quotes if they exist, then we add it again, now we're relatively certain that the values are quoted exactly once.
Here's a related issue: #6455 though at the time this was resolved, the -pa
et. al. worked just without the ~
. That would have worked for me as well, so I'm not completely certain why the tilde was introduced.
Expected behavior
C:\>"c:\Program Files\Elixir\bin\elixir.bat" "-pa" "c:/Program files" -e "IO.puts('Success!')"
Success
Somewhat duplicate of #13165. We are currently rewriting those scripts to powershell because the quoting rules in batch are just too complicate to manage in the long term. :) However, I think we should give your suggestions a try. We definitely quote everything that is sent to Erlang.
Thank you! Assuming this is working well, is there a chance that the change will be backported to previous versions?
Somewhat duplicate of #13165.
Somewhat, it might be due to
Line 101 in 11a493e
Line 156 in 11a493e
The !par!
should be quoted there... I think. Because in L93 you're using %~1
(which I think it is correct to not quote considering the later processing done.
We are currently rewriting those scripts to powershell because the quoting rules in batch are just too complicate to manage in the long term.
I'll definitely be watching out for that change, I didn't have much luck and essentially given up to get startup scripts to run properly on Windows and was planning on just writing them in a compiled language or just give in and use .net.
Let's give it a try! I pushed a PR here with your changes, feel free to poke at it: #13166