Possible bug in std.path?
Hugo via Digitalmars-d
digitalmars-d at puremagic.com
Sun Jun 19 09:21:04 PDT 2016
On Sunday, 19 June 2016 at 14:29:27 UTC, ag0aep6g wrote:
> You're calling Windows' CommandLineToArgvW here. I don't think
> that's what Adam meant by "process it yourself". If you don't
> like how CommandLineToArgvW parses the command line, don't use
> it.
What would be the efficient way to talke this then? I tried regex:
import std.stdio, std.file, std.path;
version (Windows) {
import core.sys.windows.windows, std.conv, std.regex;
pragma(lib, "shell32.lib");
}
enum EXIT_SUCCESS = 0;
enum EXIT_FAILURE = 1;
int main(string[] originalargs) {
string[] args;
version (Windows) {
SetConsoleOutputCP(65001);
static re = regex(`\s+`, "g");
auto wargs = GetCommandLineW();
if (wargs) {
args = split(text(wargs), re);
debug writefln("'%s'", text(wargs));
} else {
writeln("Error getting command line arguments.");
return EXIT_FAILURE;
}
} else args = originalargs;
foreach(uint i, string a; args) writefln("Argument %d: '%s'",
i, a);
return EXIT_SUCCESS;
}
However it doesn't quite work will all cases (besides I fear in
this case a regexp could offer an unnecessary entry point for an
exploit):
mytestapp dir1 ..\ "another dir\"
Argument 0: 'mytestapp'
Argument 1: 'dir1'
Argument 2: '..\'
Argument 3: '"another'
Argument 4: 'dir\"'
More information about the Digitalmars-d
mailing list