File tree 4 files changed +54
-4
lines changed
FluentCommandLineParser/Internals
FluentCommandLineParser.Tests
4 files changed +54
-4
lines changed Original file line number Diff line number Diff line change 83
83
<ItemGroup >
84
84
<Compile Include =" Integration\Int64InlineDataAttribute.cs" />
85
85
<Compile Include =" Integration\Lists\Int64ListInlineDataAttribute.cs" />
86
+ <Compile Include =" Internals\UsefulExtensionTests.cs" />
86
87
<Compile Include =" UriTests.cs" />
87
88
<Compile Include =" CommandLineOptionFormatterTests.cs" />
88
89
<Compile Include =" Commands\AddArgs.cs" />
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -92,9 +92,11 @@ public static string WrapInDoubleQuotes(this string str)
92
92
/// </summary>
93
93
public static string RemoveAnyWrappingDoubleQuotes ( this string str )
94
94
{
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 ;
98
100
}
99
101
100
102
/// <summary>
Original file line number Diff line number Diff line change @@ -39,7 +39,11 @@ public class StringCommandLineOptionParser : ICommandLineOptionParser<string>
39
39
/// <returns></returns>
40
40
public string Parse ( ParsedOption parsedOption )
41
41
{
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 ;
43
47
}
44
48
45
49
/// <summary>
You can’t perform that action at this time.
0 commit comments