@@ -823,7 +823,7 @@ var defaultCommandTests = []struct {
823823 {"f" , "" , nil , true },
824824 {"" , "foobar" , nil , true },
825825 {"" , "" , nil , true },
826- {" " , "" , nil , true },
826+ {" " , "" , nil , false },
827827 {"bat" , "batbaz" , nil , true },
828828 {"nothing" , "batbaz" , nil , true },
829829 {"nothing" , "" , nil , false },
@@ -911,10 +911,10 @@ var defaultCommandSubCommandTests = []struct {
911911 {"" , "carly" , "foobar" , true },
912912 {"" , "jimmers" , "foobar" , false },
913913 {"" , "jimmers" , "" , false },
914- {" " , "jimmers" , "foobar" , true },
914+ {" " , "jimmers" , "foobar" , false },
915915 {"" , "" , "" , true },
916- {" " , "" , "" , true },
917- {" " , "j" , "" , true },
916+ {" " , "" , "" , false },
917+ {" " , "j" , "" , false },
918918 {"bat" , "" , "batbaz" , false },
919919 {"nothing" , "" , "batbaz" , false },
920920 {"nothing" , "" , "" , false },
@@ -977,10 +977,10 @@ var defaultCommandFlagTests = []struct {
977977 {"" , "--carly=derp" , "foobar" , true },
978978 {"" , "-j" , "foobar" , true },
979979 {"" , "-j" , "" , true },
980- {" " , "-j" , "foobar" , true },
980+ {" " , "-j" , "foobar" , false },
981981 {"" , "" , "" , true },
982- {" " , "" , "" , true },
983- {" " , "-j" , "" , true },
982+ {" " , "" , "" , false },
983+ {" " , "-j" , "" , false },
984984 {"bat" , "" , "batbaz" , false },
985985 {"nothing" , "" , "batbaz" , false },
986986 {"nothing" , "" , "" , false },
@@ -5624,6 +5624,47 @@ func TestCommand_ExclusiveFlagsPersistent(t *testing.T) {
56245624 }
56255625}
56265626
5627+ func TestEmptyPositionalArgs (t * testing.T ) {
5628+ testCases := []struct {
5629+ Name string
5630+ Args []string
5631+ Expected []string
5632+ }{
5633+ {
5634+ Name : "empty arg between values" ,
5635+ Args : []string {"app" , "hello" , "" , "world" },
5636+ Expected : []string {"hello" , "" , "world" },
5637+ },
5638+ {
5639+ Name : "empty arg at start" ,
5640+ Args : []string {"app" , "" , "hello" },
5641+ Expected : []string {"" , "hello" },
5642+ },
5643+ {
5644+ Name : "whitespace-only arg" ,
5645+ Args : []string {"app" , "hello" , " " , "world" },
5646+ Expected : []string {"hello" , " " , "world" },
5647+ },
5648+ }
5649+
5650+ for _ , tc := range testCases {
5651+ t .Run (tc .Name , func (t * testing.T ) {
5652+ var args []string
5653+
5654+ cmd := & Command {
5655+ Action : func (_ context.Context , cmd * Command ) error {
5656+ args = cmd .Args ().Slice ()
5657+ return nil
5658+ },
5659+ }
5660+
5661+ err := cmd .Run (buildTestContext (t ), tc .Args )
5662+ assert .NoError (t , err )
5663+ assert .Equal (t , tc .Expected , args )
5664+ })
5665+ }
5666+ }
5667+
56275668func TestFlagEqualsEmptyValue (t * testing.T ) {
56285669 t .Run ("--flag= sets empty string" , func (t * testing.T ) {
56295670 var val string
0 commit comments