Skip to content

Commit d088c08

Browse files
committed
Fix snapshot name normalization for dot-dot paths
1 parent e8663de commit d088c08

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

snapshots.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
func normalizeSnapshotName(path string) string {
1515
name := filepath.Base(path)
16-
if name == "." || name == string(filepath.Separator) {
16+
if name == "." || name == ".." || name == string(filepath.Separator) {
1717
return "snapshot"
1818
}
1919
return name

snapshots_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,22 @@ func TestSnapshotRepoNormalizesTrailingDotPath(t *testing.T) {
7979
_ = RestoreSnapshot(t, snap)
8080
}
8181

82+
func TestNormalizeSnapshotNameHandlesDotDot(t *testing.T) {
83+
tests := []struct {
84+
input string
85+
want string
86+
}{
87+
{input: "..", want: "snapshot"},
88+
{input: filepath.Join("foo", ".."), want: "snapshot"},
89+
}
90+
91+
for _, tt := range tests {
92+
if got := normalizeSnapshotName(tt.input); got != tt.want {
93+
t.Fatalf("normalizeSnapshotName(%q) = %q, want %q", tt.input, got, tt.want)
94+
}
95+
}
96+
}
97+
8298
func TestLoadSnapshotFromDiskUsesBaseName(t *testing.T) {
8399
_, repo := CreateCleanRepoScenario(t)
84100
snapshot := SnapshotRepo(t, repo.path)

0 commit comments

Comments
 (0)