Skip to content

Commit eec17c7

Browse files
authored
Merge pull request #108 from oleksabor/develop
fixing #106
2 parents 61420e4 + b744050 commit eec17c7

File tree

4 files changed

+54
-4
lines changed

4 files changed

+54
-4
lines changed

FluentCommandLineParser.Tests/FluentCommandLineParser.Tests.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
<ItemGroup>
8484
<Compile Include="Integration\Int64InlineDataAttribute.cs" />
8585
<Compile Include="Integration\Lists\Int64ListInlineDataAttribute.cs" />
86+
<Compile Include="Internals\UsefulExtensionTests.cs" />
8687
<Compile Include="UriTests.cs" />
8788
<Compile Include="CommandLineOptionFormatterTests.cs" />
8889
<Compile Include="Commands\AddArgs.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using Fclp.Internals.Extensions;
2+
using NUnit.Framework;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace Fclp.Tests.Internals
10+
{
11+
/// <summary>
12+
/// option value that has double quote at the end
13+
/// </summary>
14+
[TestFixture]
15+
public class when_there_is_qoute_in_the_end
16+
{
17+
[Test]
18+
public void parser() // not sure that it should be here
19+
{
20+
var args = new[] { "--param", "something \"4\"" };
21+
22+
var sut = new Fclp.FluentCommandLineParser<Config>();
23+
sut.Setup(_ => _.Param).As('p', "param");
24+
var res = sut.Parse(args);
25+
26+
Assert.AreEqual("something \"4\"", sut.Object.Param);
27+
}
28+
29+
[Test]
30+
public void RemoveAnyWrappingDoubleQuotes()
31+
{
32+
var str = "something \"4\"";
33+
str = str.WrapInDoubleQuotes();
34+
str = str.RemoveAnyWrappingDoubleQuotes();
35+
Assert.AreEqual("something \"4\"", str);
36+
}
37+
}
38+
39+
public class Config
40+
{
41+
public string Param { get; set; }
42+
}
43+
}

FluentCommandLineParser/Internals/Extensions/UsefulExtension.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,11 @@ public static string WrapInDoubleQuotes(this string str)
9292
/// </summary>
9393
public static string RemoveAnyWrappingDoubleQuotes(this string str)
9494
{
95-
return str.IsNullOrWhiteSpace()
96-
? str
97-
: str.TrimStart('"').TrimEnd('"');
95+
96+
if (!str.IsNullOrWhiteSpace())
97+
if (str.StartsWith("\"") && str.EndsWith("\""))
98+
return str.Substring(1, str.Length - 2);
99+
return str;
98100
}
99101

100102
/// <summary>

FluentCommandLineParser/Internals/Parsing/OptionParsers/StringCommandLineOptionParser.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ public class StringCommandLineOptionParser : ICommandLineOptionParser<string>
3939
/// <returns></returns>
4040
public string Parse(ParsedOption parsedOption)
4141
{
42-
return parsedOption.Value == null ? null : parsedOption.Value.RemoveAnyWrappingDoubleQuotes();
42+
if (parsedOption.Value == null)
43+
return null;
44+
return parsedOption.Value.ContainsWhitespace()
45+
? parsedOption.Value.RemoveAnyWrappingDoubleQuotes()
46+
: parsedOption.Value;
4347
}
4448

4549
/// <summary>

0 commit comments

Comments
 (0)