commandlineparser / commandlineparser/commandline

Backslash parsing problem in argument.

Open
#918 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
C#
Stars
4.8k
Forks
478
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**
Read string option with backslash \ and " results in reading " in the string.

**To Reproduce**
```
public class Options
{
[Option('P', "path", Required = true, HelpText = "Set working directory path.")]
public string Path { get; set; }
}

static void Main(string[] args)
{
string path = "";

var result = Parser.Default.ParseArguments(args)
.WithParsed(o =>
{
path = o.Path;
});

if (result.Tag == ParserResultType.Parsed)
{
Console.WriteLine($"Path: {path}");
}
}
```
1. Passing in argument `-P "C:\path\to\read\"`
2. Console output is `Path: C:\path\to\read"`

**Expected behavior**
Read backslash as it is. In the above example, output should be `Path: C:\path\to\read\`

**Additional context**
Am i missing some options?
Ref [issues/226](https://github.com/commandlineparser/commandline/issues/226) reports the same problem, still not fixed?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the issue with the provided Options class and command-line argument, then trace the argument parsing path that handles quoted backslashes. Verify the behavior against the linked issue 226 for context. Done means a trailing backslash is preserved in the parsed Path value and the reproduction produces the expected output.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.