Open jords1987 opened 7 years ago
GetCommandLine()
is called from Program.cs
.
But the arguments are split by space because they are not quoted properly.
So each argument should be quoted using this?
So each argument should be quoted using this?
No. Please see https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/.
If the path ever happens to end in a backslash, it escapes the ending quote and you're in big trouble.
See https://gist.github.com/jnm2/c5c840bf317605a40f5f56f944db4892 for a safe implementation of argv quoting with tests.
See dotnet/corefx#23592 for a discussion of how to handle args in a cross-platform way.
In my opinion, Cake should deprecate AppendQuoted and autoquote everything passed to Append if necessary. The problem has been rampant every time I've looked.
My EscapeProcessArgument
implementation can either quote only if necessary or always.
Again, simply appending and prepending a quote character is dangerous and incorrect.
@jnm2 Thanks! Can you share your thoughts on this issue?
dotnet/corefx#23592 is a very insightful discussion and I hope Cake takes notice.
Windows is weird in that all the arguments are stuffed in a single string. Linux actually passes processes the equivalent of string[]
, not string
. So my thought is that EnvironmentHelper.GetCommandLine()
should be deleted and everything should rely on Environment.GetCommandLineArgs()
. If you don't do this, it means on Linux you're joining and resplitting and you're bound to get it wrong.
That's for consuming arguments. For producing arguments, Cake should keep everything as string[]
and wait until the last possible moment before serializing to an argv string and quoting if need be. One day we will have ProcessStartInfo.ArgumentList
and Cake should no longer let itself be responsible for serializing the array to a single string. In the meantime, Cake should follow https://github.com/dotnet/corefx/blob/5d3e42f831ec3d4c5964040e235824f779d5db53/src/Common/src/System/PasteArguments.cs#L16 rather than naive quoting.
This has been an ongoing concern of mine with the entirety of Cake. I started work towards addressing the naive quoting issue but my plate is way overfull. I sincerely hope someone does address it. It's one of the few things that I strongly believe Cake needs to fix ASAP. It's hard to fix properly because poor assumptions about quoting are baked into the Append
and AppendQuoted
etc API when what we should have been using from day one was Append()
that auto quoted when necessary.
And remember, one day, it wouldn't even be responsible for the quoting. It would just pass the list to ProcessStartInfo.ArgumentList
so that Linux passes the list of args to the process with full fidelity; it would never appear even once as a single string. And on Windows, the BCL would then take care of serializing into a single string by following the argv
rules so that the arguments are deserialized back into a string[]
in the target process with full fidelity.
I too would like to see this resolved, as it has taken me the best part of a day to work out that this limitation exists in Cake.CoreCLR. If anyone is interested in a workaround (a.k.a. hack), here is a PowerShell sample that will convert the Cake.dll path to the old-style DOS 8:3 path format:
$cakeDll = "C:\Path with spaces\cake.coreclr\0.27.2\Cake.dll"
$fso = New-Object -ComObject Scripting.FileSystemObject
$cakeDll = $fso.GetFile($cakeDll).ShortPath
& dotnet $cakeDll
Note that this has only been tested in Windows. I have not done a Linux/MacOS Bash equivalent, as I have not explored this as yet.
What You Are Seeing? When trying to debug a cake script in vs code I am seeing the "More than one build script specified" error. I think it has something to do with my working directory having a space in a folder name as when I run without a build script specified I get an IO error and it seems to be combining my working path with the path after the space (see repro steps).
What is Expected? I am expecting to be able to debug my cake script.
What version of Cake are you using? 0.23.0
Are you running on a 32 or 64 bit system? 64
What environment are you running on? Windows? Linux? Mac? Windows 7
How Did You Get This To Happen? (Steps to Reproduce)
Clone the example repo https://github.com/mholo65/cake-vscode-debug-example into a foder path with a space in the first folder i.e "c:\spaced folder\cakedebug\" and then hit F5 on vs code or, use PS:
At this point you can take the space out of the base folder and rerun build.ps1, watch the build script run.
After this put the space back in the folder name and: