File tree Expand file tree Collapse file tree 3 files changed +25
-6
lines changed Expand file tree Collapse file tree 3 files changed +25
-6
lines changed Original file line number Diff line number Diff line change @@ -1975,6 +1975,25 @@ public void Argument_with_custom_collection_type_converter_can_be_bound()
19751975 instance . Should ( ) . BeEquivalentTo ( "a" , "b" , "c" ) ;
19761976 }
19771977
1978+ [ Fact ]
1979+ public void Tokens_are_not_split_if_the_part_before_the_delimiter_is_not_an_option ( )
1980+ {
1981+ var rootCommand = new RootCommand
1982+ {
1983+ Name = "jdbc"
1984+ } ;
1985+ rootCommand . Add ( new Option < string > ( "url" ) ) ;
1986+ var result = rootCommand . Parse ( "jdbc url \" jdbc:sqlserver://10.0.0.2;databaseName=main\" " ) ;
1987+
1988+ _output . WriteLine ( result . ToString ( ) ) ;
1989+
1990+ result . Tokens
1991+ . Select ( t => t . Value )
1992+ . Should ( )
1993+ . BeEquivalentTo ( "url" ,
1994+ "jdbc:sqlserver://10.0.0.2;databaseName=main" ) ;
1995+ }
1996+
19781997 [ TypeConverter ( typeof ( CustomTypeConverter ) ) ]
19791998 public class ClassWithCustomTypeConverter
19801999 {
Original file line number Diff line number Diff line change 33
44using System . Collections . Generic ;
55using System . CommandLine . Binding ;
6- using System . Diagnostics ;
76using System . Linq ;
87using System . Reflection ;
98using System . Threading . Tasks ;
Original file line number Diff line number Diff line change @@ -68,7 +68,7 @@ internal static TokenizeResult Tokenize(
6868 var foundEndOfDirectives = ! configuration . EnableDirectives ;
6969 var argList = NormalizeRootCommand ( configuration , args ) ;
7070
71- var argumentDelimiters = configuration . ArgumentDelimitersInternal ;
71+ var argumentDelimiters = configuration . ArgumentDelimitersInternal . ToArray ( ) ;
7272
7373 var knownTokens = configuration . RootCommand . ValidTokens ( ) ;
7474
@@ -125,7 +125,8 @@ internal static TokenizeResult Tokenize(
125125 out var first ,
126126 out var rest ) )
127127 {
128- if ( knownTokens . ContainsKey ( first ! ) )
128+ if ( knownTokens . TryGetValue ( first ! , out var token ) &&
129+ token . Type == TokenType . Option )
129130 {
130131 tokenList . Add ( Option ( first ! ) ) ;
131132
@@ -412,13 +413,13 @@ bool FirstArgMatchesRootCommand()
412413
413414 internal static bool TrySplitIntoSubtokens (
414415 this string arg ,
415- IReadOnlyCollection < char > delimiters ,
416+ char [ ] delimiters ,
416417 out string ? first ,
417418 out string ? rest )
418419 {
419- var delimitersArray = delimiters . ToArray ( ) ;
420+ var delimitersArray = delimiters ;
420421
421- for ( var j = 0 ; j < delimiters . Count ; j ++ )
422+ for ( var j = 0 ; j < delimiters . Length ; j ++ )
422423 {
423424 var i = arg . IndexOfAny ( delimitersArray ) ;
424425
You can’t perform that action at this time.
0 commit comments