diff --git a/routers/repo/wiki.go b/routers/repo/wiki.go index bf8ac658ae7c0..02fbe4a1ddad6 100644 --- a/routers/repo/wiki.go +++ b/routers/repo/wiki.go @@ -8,6 +8,7 @@ package repo import ( "fmt" "io/ioutil" + "net/url" "path/filepath" "strings" @@ -68,11 +69,22 @@ func findEntryForFile(commit *git.Commit, target string) (*git.TreeEntry, error) if err != nil { return nil, err } + // The longest name should be checked first for _, entry := range entries { if entry.IsRegular() && entry.Name() == target { return entry, nil } } + // Then the unescaped, shortest alternative + var unescapedTarget string + if unescapedTarget, err = url.QueryUnescape(target); err != nil { + return nil, err + } + for _, entry := range entries { + if entry.IsRegular() && entry.Name() == unescapedTarget { + return entry, nil + } + } return nil, nil }