diff --git a/builder/common/config.go b/builder/common/config.go index 1eab19375..94b03e2b1 100644 --- a/builder/common/config.go +++ b/builder/common/config.go @@ -2,11 +2,11 @@ package common import ( "fmt" - "path/filepath" "github.com/mitchellh/mapstructure" "github.com/mitchellh/packer/packer" "net/url" "os" + "path/filepath" "sort" "strings" ) @@ -97,7 +97,7 @@ func DownloadableURL(original string) (string, error) { // we distribute with a version of Go that fixes that bug. // // See: https://code.google.com/p/go/issues/detail?id=5927 - if url.Path[0] != '/' { + if url.Path != "" && url.Path[0] != '/' { url.Path = "/" + url.Path } diff --git a/builder/common/config_test.go b/builder/common/config_test.go index 2a337f5c6..e7f469bcc 100644 --- a/builder/common/config_test.go +++ b/builder/common/config_test.go @@ -88,6 +88,16 @@ func TestDownloadableURL(t *testing.T) { if u != "http://packer.io/path" { t.Fatalf("bad: %s", u) } + + // No path + u, err = DownloadableURL("HTTP://packer.io") + if err != nil { + t.Fatalf("err: %s", err) + } + + if u != "http://packer.io" { + t.Fatalf("bad: %s", u) + } } func TestDownloadableURL_FilePaths(t *testing.T) {