argtable / argtable3

A single-file, ANSI C, command-line parsing library that parses GNU-style command-line options.
http://www.argtable.org
Other
372 stars 65 forks source link

Parsing issue: trailing backslash with spaced paths #18

Closed clintonbale closed 4 years ago

clintonbale commented 6 years ago

System: Windows

When passing an string argument to a command line application that ends with backslash, the trailing quote is escaped.

Reproducible by simply having an arg_filen argument that takes in a file path. Multiple arg_filen parameters with multiple quoted paths are not parsable and results in an error (example test-path.zip)

single file

input: test.exe "C:\test folder\" path1 = C:\test folder"

multiple files

input: test.exe "C:\test folder\" "C:\test folder2\" path1 = C:\test folder" C:\test path2 = folder2"

Let me know if you require additional information.

tomghuang commented 4 years ago

The issue is caused by Microsoft command-line parameter parsing rules in the CreateProcess() Win32 API. If you output argv of the following command line:

C:\> test "C:\test folder\" "C:\test folder2\"

You will see the following output:

argv[0]: test
argv[1]: C:\test folder" C:\test
argv[2]: folder2"

It means that before passing to Argtable3, the system already splits the parameters in the way that we don't expect. You can see more information about Microsoft command-line parameter parsing rules in the following page: http://www.daviddeley.com/autohotkey/parameters/parameters.htm#WINCRULESDOC

To resolve this issue, we have to either remove the trailing backslash from the path names, or add an additional backslash:

C:\> test "C:\test folder\\" "C:\test folder2\\"