packer: don't crash if arg is empty [GH-832]

This commit is contained in:
Mitchell Hashimoto 2014-01-19 15:19:10 -08:00
parent 602ed10e89
commit 3857822ef2
3 changed files with 9 additions and 1 deletions

View File

@ -2,6 +2,7 @@
BUG FIXES:
* core: Fix crash case if blank parameters are given to Packer. [GH-832]
* builders/docker: user variables work properly. [GH-777]
* builder/virtualbox,vmware: iso\_checksum is not required if the
checksum type is "none"

View File

@ -221,7 +221,7 @@ func (e *coreEnvironment) Cli(args []string) (result int, err error) {
// Trim up to the command name
for i, v := range args {
if v[0] != '-' {
if len(v) > 0 && v[0] != '-' {
args = args[i:]
break
}

View File

@ -198,10 +198,17 @@ func TestEnvironment_Cli_CallsRun(t *testing.T) {
func TestEnvironment_DefaultCli_Empty(t *testing.T) {
defaultEnv := testEnvironment()
// Test with no args
exitCode, _ := defaultEnv.Cli([]string{})
if exitCode != 1 {
t.Fatalf("bad: %d", exitCode)
}
// Test with only blank args
exitCode, _ = defaultEnv.Cli([]string{""})
if exitCode != 1 {
t.Fatalf("bad: %d", exitCode)
}
}
func TestEnvironment_DefaultCli_Help(t *testing.T) {