Skip to content

In elixir.bat some argument values are not properly quoted #13565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
E14 opened this issue May 17, 2024 · 3 comments
Closed

In elixir.bat some argument values are not properly quoted #13565

E14 opened this issue May 17, 2024 · 3 comments

Comments

@E14
Copy link

E14 commented May 17, 2024

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:

elixir/bin/elixir.bat

Lines 132 to 135 in 6f84158

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)

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
@josevalim
Copy link
Member

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.

@E14
Copy link
Author

E14 commented May 17, 2024

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

set parsElixir=!parsElixir! !par!
and
set parsElixir=!parsElixir! !par!

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.

@josevalim
Copy link
Member

Let's give it a try! I pushed a PR here with your changes, feel free to poke at it: #13166

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants