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 {
|
func (f *FileCache) cachePath(key string, hashKey string) string {
|
||||||
suffix := ""
|
suffix := ""
|
||||||
dotIndex := strings.LastIndex(key, ".")
|
endIndex := strings.Index(key, "?")
|
||||||
if dotIndex > -1 {
|
if endIndex == -1 {
|
||||||
suffix = key[dotIndex:len(key)]
|
endIndex = len(key)
|
||||||
|
}
|
||||||
|
|
||||||
idx := strings.Index(suffix, "?")
|
dotIndex := strings.LastIndex(key[0:endIndex], ".")
|
||||||
if idx != -1 {
|
if dotIndex > -1 {
|
||||||
suffix = suffix[0:idx]
|
suffix = key[dotIndex:endIndex]
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return filepath.Join(f.CacheDir, hashKey+suffix)
|
return filepath.Join(f.CacheDir, hashKey+suffix)
|
||||||
|
|
|
@ -37,8 +37,8 @@ func TestFileCache(t *testing.T) {
|
||||||
defer os.RemoveAll(cacheDir)
|
defer os.RemoveAll(cacheDir)
|
||||||
|
|
||||||
cache := &FileCache{CacheDir: cacheDir}
|
cache := &FileCache{CacheDir: cacheDir}
|
||||||
path := cache.Lock("foo.ext?foo=bar")
|
path := cache.Lock("foo.ext?foo=bar.foo")
|
||||||
defer cache.Unlock("foo.ext?foo=bar")
|
defer cache.Unlock("foo.ext?foo=bar.foo")
|
||||||
if !strings.HasSuffix(path, ".ext") {
|
if !strings.HasSuffix(path, ".ext") {
|
||||||
t.Fatalf("bad extension with question mark: %s", path)
|
t.Fatalf("bad extension with question mark: %s", path)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue