-
Notifications
You must be signed in to change notification settings - Fork 3
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
CommandLine #1
Comments
No I didn't know about it :) The code I uploaded here is actually very old, started as some personnal project in F#, then cleaned up to be used in some modules at work including some FAKE ones (I was always annoyed that most FAKE modules uses incorrect escaping) It even has a C# port that I made for the paket bootstrapper (That's were it gained the reverse capacity of parsing command line because I never used it elsewhere) One thing our work codebase has that I don't have here is the possibility to use The one missing thing in this code is to reverse mono & .Net core algorithms on linux/mac. On these platforms there is no (Microsoft has planned add APIs to .Net core to transmit arrays directly, but there was a lot of discussions about what to do on windows, do they implement reverse MSVCRT like here and if yes what version or just throw an exception) |
I tried to run my test suite on your code and here are the differences :
let escapeTests = [
test "Odd_backslash_escaped" {
verifyEscape @"""a\\\\b c"" d e" [@"a\\b c"; "d"; "e"]
}
test "Even_backslash_escaped" {
verifyEscape @"""a\\\\\b c"" d e" [@"a\\\b c"; "d"; "e"]
}
] I just added a property-based test that at least prove that the lib is reversable one way : 7b6ea76#diff-0d92d8a37f6bc8f0633870d6d9c57b20R159 (The other way is more annoying to test as the information that an argument was quoted or not is lost in the transformation) |
Funny IIRC my implementation is basically a strict port of https://github.com/dotnet/corefx/blob/ed4e3eafae1f454011732cadf734060c8e262c59/src/System.Diagnostics.Process/src/System/Diagnostics/Process.Unix.cs#L548-L640 which is exactly what .net core is doing (which should be relevant here) Also
Seems to conform with https://docs.microsoft.com/de-de/cpp/cpp/parsing-cpp-command-line-arguments
|
Hm I tried to reproduce the double quoting stuff:
So maybe they have changed that again in the mean time and this only hits "old" programs? At least for FSI/.NET double quotes behave according to documentation (ie open and close an empty argument) |
Ah yes thanks 👍 my lib is wrong as I applied all tests reversely now and theses fail. It's supposed to only do that before double quotes. I'll fix that code but need the C# version of the fix too for the paket bootstrapper
The case is this one (There are more complex ones but they can't easily be expressed on the command line as cmd parser interferes, need to call CreateProcess/Process.Start directly): g:\Code\_ext\FAKE>echo printfn^ ^"^%A^" ^(System.Environment.GetCommandLineArgs^(^)^) | fsi -- test ^"^"^"Call Me Ishmael^"^"^"
Microsoft (R) F# Interactive version 10.1.0 for F# 4.1
Copyright (c) Microsoft Corporation. All Rights Reserved.
For help type #help;;
> [|"fsi"; "--"; "test"; ""Call Me Ishmael""|]
val it : unit = () and: let s = CmdLineParsing.windowsCommandLineToArgv @"""""""CallMeIshmael"""""""
printfn "%A" s
// [|"CallMeIshmael"|] The result of parsing |
Ok I guess I'll have to think about that and test around. However, I also think this shouldn't have any impact for the use case of fake. Realistically we only use the array->string conversation and the string->array conversation only to revert the first. Both shouldn't be hit by either one of the special cases. Therefore we might consider leaving as is which conforms to official documentation. |
Yes, the more logical escaping for quotes is So whenever they are implemented or not isn't that important. |
@matthid BTW why are most FAKE module still using the |
0.1.1 published with the fix for the |
Well I tried to point people to it while migration but for at first the runtime and getting things to bootstrap was my priority later I wanted to get the damn thing released instead of reworking all modules again This might be something for fake 6, for now the runtime and getting things modularized and manageable was more important in the end ;) It boils down to too few time and people.. |
Anyway thanks for the insights I'd assume they will come in handy at one time ;) |
- fix edge case with empty quotes, see vbfox/FoxSharp#1 - do not handle tripple quotes, see vbfox/FoxSharp#1 thanks @vbfox
In fact the property based test found an issue with empty arguments in the fake implementation: the argument list |
👍 On the fact that FAKE don't use it I was mainly asking because I wondered when porting squirrel if I should propose the use of my lib but the API is young and might need work, but if I knew there was an equivalent in FAKE itself I would have done the porting. (The first real usage of this lib btw was for an internal fork of the dotcover FAKE module as it embed other tools cmd lines in it's own escaping can become a problem pretty fast, never contributed it back because it was quite a change and our fork is also messed up by various investigation into the nunit error while tearing down appdomain shitshow) |
Funny on the empty arguments, it was broken in my first impl in the other direction and someone fixed it in paket : fsprojects/Paket#2551 |
Did you notice https://github.com/fsharp/FAKE/blob/release/next/src/app/Fake.Core.Process/CmdLineParsing.fs?
are there any issues compared to https://github.com/vbfox/FoxSharp/blob/master/src/BlackFox.CommandLine/MsvcrCommandLine.fs
At least I tried to come up with a fully conforming implementation according to Microsoft documentation, but hey you never know they have really strange rules :)
The text was updated successfully, but these errors were encountered: