Commit 3ae0b2f0 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/common: Don't prepend slash to URL path if path is empty

parent c06c1fee
...@@ -2,11 +2,11 @@ package common ...@@ -2,11 +2,11 @@ package common
import ( import (
"fmt" "fmt"
"path/filepath"
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"net/url" "net/url"
"os" "os"
"path/filepath"
"sort" "sort"
"strings" "strings"
) )
...@@ -97,7 +97,7 @@ func DownloadableURL(original string) (string, error) { ...@@ -97,7 +97,7 @@ func DownloadableURL(original string) (string, error) {
// we distribute with a version of Go that fixes that bug. // we distribute with a version of Go that fixes that bug.
// //
// See: https://code.google.com/p/go/issues/detail?id=5927 // 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 url.Path = "/" + url.Path
} }
......
...@@ -88,6 +88,16 @@ func TestDownloadableURL(t *testing.T) { ...@@ -88,6 +88,16 @@ func TestDownloadableURL(t *testing.T) {
if u != "http://packer.io/path" { if u != "http://packer.io/path" {
t.Fatalf("bad: %s", u) 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) { func TestDownloadableURL_FilePaths(t *testing.T) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment