packer: Properly handle ? in URLs in cache keys
/cc @sit - Found another edge case
This commit is contained in:
parent
e3478c38ef
commit
38ae1a0ba9
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue