crystal-lang / crystal

The Crystal Programming Language
https://crystal-lang.org
Apache License 2.0
19.26k stars 1.61k forks source link

Disable implicit execution of batch files on Windows #14557

Closed straight-shoota closed 2 months ago

straight-shoota commented 2 months ago

This patch disables the implicit execution of batch files (i.e. path name extension .bat or .cmd, case-insensitive) in Process.run on Windows with shell: false (default). There are no effects on other operating systems. The disabled behaviour is an irrational and potentially dangerous feature of CreateProcessW which is not intended for Process.run.

If you want to run a batch file on Windows, you need to launch it through a shell, either implicitly with shell: true or explicitly by running cmd.exe with the batch file as argument. The semantics are different on POSIX platforms where you can directly execute a shell script if it has a shebang. The mechanism on Windows works differently, as CreateProcessW implicitly injects cmd.exe /c which changes the semantics of run arguments.

A similar approach has been taken by node.js: https://github.com/nodejs/node/commit/64b67779f72ea9e4a0f444284576df9e591d79a0

Resolves #14536