Skip to content

Commit 58ff61e

Browse files
authored
Merge pull request #55 from montgomerybc/argument-values-start-with-non-word-character
Support Arguments values starting with non-word chars
2 parents 1f28c83 + de025db commit 58ff61e

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/Utility.CommandLine.Arguments/Arguments.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public class Arguments
176176
/// <summary>
177177
/// The regular expression with which to parse the command line string.
178178
/// </summary>
179-
private const string ArgumentRegEx = "(?:[-]{1,2}|\\/)([^=: ]+)[=: ]?(\\/?\\w\\S*|\\\"[^\"]*\\\"|\\\'[^']*\\\')?|([^ ([^'\\\"]+|\"[^\\\"]+\"|\\\'[^']+\\\')";
179+
private const string ArgumentRegEx = "(?:[-]{1,2}|\\/)([^=: ]+)[=: ]?(\\/?[^-'\"]\\S*|\\\"[^\"]*\\\"|\\\'[^']*\\\')?|([^ ([^'\\\"]+|\"[^\\\"]+\"|\\\'[^']+\\\')";
180180

181181
/// <summary>
182182
/// The regular expression with which to parse argument-value groups.

tests/Utility.CommandLine.Arguments.Tests/ArgumentsTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,25 @@ public void ParseValueWithQuotedPeriod()
383383
Assert.Equal("test2.test2", test["test2"]);
384384
}
385385

386+
[Theory]
387+
[InlineData(".")]
388+
[InlineData("..")]
389+
[InlineData("..\\")]
390+
[InlineData(".\\foo")]
391+
[InlineData("..\\foo")]
392+
[InlineData("..\\..")]
393+
[InlineData("\\")]
394+
[InlineData("\\foo")]
395+
[InlineData("\\foo\\bar")]
396+
[InlineData("\\\\foo")]
397+
[InlineData("\\\\foo\\bar")]
398+
public void ParseValueStartingWithNonWord(string value)
399+
{
400+
Dictionary<string, object> test = Arguments.Parse($"-f {value}").ArgumentDictionary;
401+
402+
Assert.Equal(value, test["f"]);
403+
}
404+
386405
[Fact]
387406
public void Populate()
388407
{

0 commit comments

Comments
 (0)