Skip to content

Commit d6819d2

Browse files
authored
Merge pull request #63 from jpdillingham/develop
Disable forward slash as argument delimiter by default
2 parents 750a47b + 7c594d4 commit d6819d2

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

src/Utility.CommandLine.Arguments/Arguments.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,12 @@ 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}|\\/)([^=: ]+)[=: ]?([^-'\"\\/]\\S*|\\\"[^\"]*\\\"|\\\'[^']*\\\')?|([^ ([^'\\\"]+|\"[^\\\"]+\"|\\\'[^']+\\\')";
179+
private const string ArgumentRegExWithoutForwardSlash = "(?:[-]{1,2})([^=: ]+)[=: ]?([^-'\"]\\S*|\\\"[^\"]*\\\"|\\\'[^']*\\\')?|([^ ([^'\\\"]+|\"[^\\\"]+\"|\\\'[^']+\\\')";
180+
181+
/// <summary>
182+
/// The regular expression with which to parse the command line string, including the ability to specify forward slashes.
183+
/// </summary>
184+
private const string ArgumentRegExWithForwardSlash = "(?:[-]{1,2}|\\/)([^=: ]+)[=: ]?([^-'\"\\/]\\S*|\\\"[^\"]*\\\"|\\\'[^']*\\\')?|([^ ([^'\\\"]+|\"[^\\\"]+\"|\\\'[^']+\\\')";
180185

181186
/// <summary>
182187
/// The regular expression with which to parse argument-value groups.
@@ -207,6 +212,11 @@ private Arguments(string commandLineString, List<KeyValuePair<string, string>> a
207212
TargetType = targetType;
208213
}
209214

215+
/// <summary>
216+
/// Gets or sets a value indicating whether forward slashes are processed as argument delimiters.
217+
/// </summary>
218+
public static bool EnableForwardSlash { get; set; } = false;
219+
210220
/// <summary>
211221
/// Gets a dictionary containing the arguments and values specified in the command line arguments with which the
212222
/// application was started.
@@ -242,6 +252,8 @@ private Arguments(string commandLineString, List<KeyValuePair<string, string>> a
242252
/// </summary>
243253
public Type TargetType { get; }
244254

255+
private static string ArgumentRegEx => EnableForwardSlash ? ArgumentRegExWithForwardSlash : ArgumentRegExWithoutForwardSlash;
256+
245257
/// <summary>
246258
/// Gets the argument value corresponding to the specified <paramref name="index"/>.
247259
/// </summary>

src/Utility.CommandLine.Arguments/Utility.CommandLine.Arguments.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
@@ -11,7 +11,7 @@
1111

1212
<PropertyGroup>
1313
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
14-
<Version>4.0.0</Version>
14+
<Version>5.0.0</Version>
1515
<Authors>JP Dillingham</Authors>
1616
<Product>Utility.CommandLine.Arguments</Product>
1717
<PackageProjectUrl>https://github.com/jpdillingham/Utility.CommandLine.Arguments</PackageProjectUrl>

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public void ParseInnerQuotedStrings()
197197
[Fact]
198198
public void ParseLongAndShortMix()
199199
{
200-
Dictionary<string, object> test = Arguments.Parse("--one=1 -ab 2 /three:3 -4 4").ArgumentDictionary;
200+
Dictionary<string, object> test = Arguments.Parse("--one=1 -ab 2 --three:3 -4 4").ArgumentDictionary;
201201

202202
Assert.Equal("1", test["one"]);
203203
Assert.True(test.ContainsKey("a"));
@@ -355,7 +355,7 @@ public void ParseStrictOperandsStart()
355355
[Fact]
356356
public void ParseStringOfLongs()
357357
{
358-
Dictionary<string, object> test = Arguments.Parse("--one 1 --two=2 /three:3 --four \"4 4\" --five='5 5'").ArgumentDictionary;
358+
Dictionary<string, object> test = Arguments.Parse("--one 1 --two=2 --three:3 --four \"4 4\" --five='5 5'").ArgumentDictionary;
359359

360360
Assert.NotEmpty(test);
361361
Assert.Equal(5, test.Count);
@@ -395,6 +395,15 @@ public void ParseValueWithQuotedPeriod()
395395
[InlineData("\\foo\\bar")]
396396
[InlineData("\\\\foo")]
397397
[InlineData("\\\\foo\\bar")]
398+
[InlineData("..//")]
399+
[InlineData(".//foo")]
400+
[InlineData("..//foo")]
401+
[InlineData("..//..")]
402+
[InlineData("//")]
403+
[InlineData("//foo")]
404+
[InlineData("//foo//bar")]
405+
[InlineData("////foo")]
406+
[InlineData("////foo//bar")]
398407
public void ParseValueStartingWithNonWord(string value)
399408
{
400409
Dictionary<string, object> test = Arguments.Parse($"-f {value}").ArgumentDictionary;
@@ -1100,12 +1109,11 @@ public class TestWithAllBools
11001109
[InlineData("-abc")]
11011110
[InlineData("-a -b -c")]
11021111
[InlineData("--aa --bb --cc")]
1103-
[InlineData("/a /b /c")]
1104-
[InlineData("/aa /bb /cc")]
1105-
[InlineData("-a --bb /c")]
1106-
[InlineData("--aa -b /c")]
1107-
[InlineData("/a /b -c")]
1108-
[InlineData("-a /bb --cc")]
1112+
[InlineData("-a -b -c")]
1113+
[InlineData("--aa --bb --cc")]
1114+
[InlineData("-a --bb -c")]
1115+
[InlineData("--aa -b -c")]
1116+
[InlineData("-a --bb --cc")]
11091117
public void PopulateStackedBools(string str)
11101118
{
11111119
Arguments.Populate(GetType(), str);

0 commit comments

Comments
 (0)