Skip to content

Commit 6368106

Browse files
Merge pull request #2437 from turetske/link-header-depth
Fix link depth header for listings
2 parents 3c4d54f + 712bffe commit 6368106

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

director/director.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,11 @@ func getLinkDepth(filepath, prefix string) (int, error) {
204204
// To make the final calculation easier, we also remove the head slash from the file path.
205205
// e.g. filepath = /foo/bar/barz.txt prefix = /foo
206206
// we want commonPath = bar/barz.txt
207-
if !strings.HasSuffix(prefix, "/") && prefix != "/" {
208-
prefix += "/"
209-
}
210207
commonPath := strings.TrimPrefix(filepath, prefix)
208+
commonPath = strings.TrimPrefix(commonPath, "/")
209+
if len(commonPath) == 0 {
210+
return 0, nil
211+
}
211212
pathDepth := len(strings.Split(commonPath, "/"))
212213
return pathDepth, nil
213214
}

director/director_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ func TestGetLinkDepth(t *testing.T) {
121121
prefix: "/foo",
122122
depth: 1,
123123
},
124+
{
125+
name: "exact-match",
126+
filepath: "/foo/bar",
127+
prefix: "/foo/bar",
128+
depth: 0,
129+
},
124130
}
125131

126132
for _, tt := range tests {

0 commit comments

Comments
 (0)