packer: Properly handle ? in URLs in cache keys

/cc @sit - Found another edge case
This commit is contained in:
Mitchell Hashimoto 2013-07-20 19:20:29 -07:00
parent e3478c38ef
commit 38ae1a0ba9
2 changed files with 9 additions and 9 deletions

View File

@ -73,14 +73,14 @@ func (f *FileCache) RUnlock(key string) {
func (f *FileCache) cachePath(key string, hashKey string) string {
suffix := ""
dotIndex := strings.LastIndex(key, ".")
if dotIndex > -1 {
suffix = key[dotIndex:len(key)]
endIndex := strings.Index(key, "?")
if endIndex == -1 {
endIndex = len(key)
}
idx := strings.Index(suffix, "?")
if idx != -1 {
suffix = suffix[0:idx]
}
dotIndex := strings.LastIndex(key[0:endIndex], ".")
if dotIndex > -1 {
suffix = key[dotIndex:endIndex]
}
return filepath.Join(f.CacheDir, hashKey+suffix)

View File

@ -37,8 +37,8 @@ func TestFileCache(t *testing.T) {
defer os.RemoveAll(cacheDir)
cache := &FileCache{CacheDir: cacheDir}
path := cache.Lock("foo.ext?foo=bar")
defer cache.Unlock("foo.ext?foo=bar")
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)
}