Skip to content

Commit 4f3173b

Browse files
committed
Decompressors should check for "." in extension
Fixes hashicorp/terraform#11438 Decompressors were suffix checking only for the extension WITHOUT a period. This was causing directories and files ending with that to be treated as an archive incorrectly.
1 parent cc80f38 commit 4f3173b

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func (c *Client) Get() error {
153153
// We don't appear to... but is it part of the filename?
154154
matchingLen := 0
155155
for k, _ := range decompressors {
156-
if strings.HasSuffix(u.Path, k) && len(k) > matchingLen {
156+
if strings.HasSuffix(u.Path, "."+k) && len(k) > matchingLen {
157157
archiveV = k
158158
matchingLen = len(k)
159159
}

get_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,21 @@ func TestGet_file(t *testing.T) {
3131
}
3232
}
3333

34+
// https://github.com/hashicorp/terraform/issues/11438
35+
func TestGet_fileDecompressorExt(t *testing.T) {
36+
dst := tempDir(t)
37+
u := testModule("basic-tgz")
38+
39+
if err := Get(dst, u); err != nil {
40+
t.Fatalf("err: %s", err)
41+
}
42+
43+
mainPath := filepath.Join(dst, "main.tf")
44+
if _, err := os.Stat(mainPath); err != nil {
45+
t.Fatalf("err: %s", err)
46+
}
47+
}
48+
3449
// https://github.com/hashicorp/terraform/issues/8418
3550
func TestGet_filePercent2F(t *testing.T) {
3651
dst := tempDir(t)

test-fixtures/basic-tgz/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Hello

0 commit comments

Comments
 (0)