Skip to content

Windows launch arguments are corrupted (double backslashes) #233

@Eugenij-W

Description

@Eugenij-W

debugee:

static void Main(string[] args) {
    using (System.IO.StreamWriter sw = new System.IO.StreamWriter(@"C:\tmp\cs.log", true, System.Text.Encoding.UTF8)) {
        for (int i = 0; i < args.Length; i++) {
            sw.WriteLine($"args[{i}]: [{args[i]}]");
        }
    }

dap log:

{"adapter": "netcoredbg", "configuration": {"type": "coreclr", "request": "launch", "program": "dotnet.exe", "args": ["bin\\Debug\\net8.0-windows\\test.dll", "D:\\path\\to\\dir\\"], "cwd": "K:\\PROJECTS\\test", "stopAtEntry": true, "console": "internalConsole"}}

cs.log:

args[0]: [D:\\path\\to\\dir\]

Please note the missing slash at the end and the duplication of other slashes.

It seems that this function does not take into account Windows specifics:

static std::string EscapeShellArg(const std::string &arg)
{
std::string s(arg);
for (std::string::size_type i = 0; i < s.size(); ++i)
{
std::string::size_type count = 0;
char c = s.at(i);
switch (c)
{
case '\"': count = 1; s.insert(i, count, '\\'); s[i + count] = '\"'; break;
case '\\': count = 1; s.insert(i, count, '\\'); s[i + count] = '\\'; break;
}
i += count;
}
return s;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions