kscripting / kscript

Scripting enhancements for Kotlin
MIT License
2.07k stars 124 forks source link

quote kotlinc path on windows (fixes #397) #398

Closed ckaag closed 1 year ago

ckaag commented 1 year ago

As explained in #397 and here https://stackoverflow.com/a/356014/1907778 cmd /c has problems with spaces in paths, which normally can be corrected in cmd / bat using double quotes. But if using some argument with cmd /c <argument>, the behavior is special for backwards compatibility if the first character is a double quote, in which case it will remove this first character as well as the last double quote in the argument, completely breaking the existing quotations.

Alternatives I have not taken:

Instead, this PR just prefixes the quoted path with a space character, disabling this special cmd mode. The now also quoted path is read in correctly, even if it contains spaces. A prefixed space outside quotation marks is effectively ignored even in cmd's command mode. Because this workaround is only needed on Windows while using cmd, it's using an if.

Because there would now be 5 identical when expressions in the class to determine which quotes to use, as well as two different string concatenations, both have been simplified into a simple val and template interpolation on all 5 instances.

I might oversee some edge case, so any pointers would be more than welcome.