@@ -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 },
@@ -5575,3 +5575,44 @@ func TestCommand_ExclusiveFlagsPersistent(t *testing.T) {
55755575 })
55765576 }
55775577}
5578+
5579+ func TestEmptyPositionalArgs (t * testing.T ) {
5580+ testCases := []struct {
5581+ Name string
5582+ Args []string
5583+ Expected []string
5584+ }{
5585+ {
5586+ Name : "empty arg between values" ,
5587+ Args : []string {"app" , "hello" , "" , "world" },
5588+ Expected : []string {"hello" , "" , "world" },
5589+ },
5590+ {
5591+ Name : "empty arg at start" ,
5592+ Args : []string {"app" , "" , "hello" },
5593+ Expected : []string {"" , "hello" },
5594+ },
5595+ {
5596+ Name : "whitespace-only arg" ,
5597+ Args : []string {"app" , "hello" , " " , "world" },
5598+ Expected : []string {"hello" , " " , "world" },
5599+ },
5600+ }
5601+
5602+ for _ , tc := range testCases {
5603+ t .Run (tc .Name , func (t * testing.T ) {
5604+ var args []string
5605+
5606+ cmd := & Command {
5607+ Action : func (_ context.Context , cmd * Command ) error {
5608+ args = cmd .Args ().Slice ()
5609+ return nil
5610+ },
5611+ }
5612+
5613+ err := cmd .Run (buildTestContext (t ), tc .Args )
5614+ assert .NoError (t , err )
5615+ assert .Equal (t , tc .Expected , args )
5616+ })
5617+ }
5618+ }
0 commit comments