diff --git a/CHANGELOG.md b/CHANGELOG.md index 18441b9f2..ab09cc744 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,8 @@ BUG FIXES: * core: No colored output in machine-readable output. [GH-684] * core: User variables can now be used for non-string fields. [GH-598] +* core: Fix bad download paths if the download URL contained a "." + before a "/" [GH-716] * builder/virtualbox: don't download guest additions if disabled. [GH-731] * post-processor/vsphere: Uploads VM properly. [GH-694] * post-processor/vsphere: Process user variables. diff --git a/packer/cache.go b/packer/cache.go index 85a23e084..a9bd4a62b 100644 --- a/packer/cache.go +++ b/packer/cache.go @@ -72,15 +72,16 @@ func (f *FileCache) RUnlock(key string) { } func (f *FileCache) cachePath(key string, hashKey string) string { - suffix := "" - endIndex := strings.Index(key, "?") - if endIndex == -1 { - endIndex = len(key) + if endIndex := strings.Index(key, "?"); endIndex > -1 { + key = key[:endIndex] } - dotIndex := strings.LastIndex(key[0:endIndex], ".") + suffix := "" + dotIndex := strings.LastIndex(key, ".") if dotIndex > -1 { - suffix = key[dotIndex:endIndex] + if slashIndex := strings.LastIndex(key, "/"); slashIndex <= dotIndex { + suffix = key[dotIndex:] + } } return filepath.Join(f.CacheDir, hashKey+suffix) diff --git a/packer/cache_test.go b/packer/cache_test.go index 306226cf9..e4463e61d 100644 --- a/packer/cache_test.go +++ b/packer/cache_test.go @@ -37,12 +37,22 @@ func TestFileCache(t *testing.T) { defer os.RemoveAll(cacheDir) cache := &FileCache{CacheDir: cacheDir} - path := cache.Lock("foo.ext?foo=bar.foo") + + // Test path with no extension (GH-716) + path := cache.Lock("/foo.bar/baz") + defer cache.Unlock("/foo.bar/baz") + if strings.Contains(path, ".bar") { + t.Fatalf("bad: %s", path) + } + + // Test paths with a ? + path = cache.Lock("foo.ext?foo=bar.foo") defer cache.Unlock("foo.ext?foo=bar.foo") if !strings.HasSuffix(path, ".ext") { t.Fatalf("bad extension with question mark: %s", path) } + // Test normal paths path = cache.Lock("foo.iso") if !strings.HasSuffix(path, ".iso") { t.Fatalf("path doesn't end with suffix '%s': '%s'", ".iso", path)