Skip to content

Commit b661659

Browse files
Tekaohguillep2k
authored andcommitted
Check for either escaped or unescaped wiki filenames (#8408)
* Check for either escaped or unescaped wiki filenames + Gitea currently saves wiki pages with escaped filenames. + Wikis mirrored from other places like Github use unescaped filenames. + We need to be checking for filenames in either format to increase compatibility. * Better logic for escaped and unescaped wiki filenames Co-Authored-By: null <guillep2k@users.noreply.github.com>
1 parent 7ad46cc commit b661659

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

routers/repo/wiki.go

+12
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package repo
88
import (
99
"fmt"
1010
"io/ioutil"
11+
"net/url"
1112
"path/filepath"
1213
"strings"
1314

@@ -68,11 +69,22 @@ func findEntryForFile(commit *git.Commit, target string) (*git.TreeEntry, error)
6869
if err != nil {
6970
return nil, err
7071
}
72+
// The longest name should be checked first
7173
for _, entry := range entries {
7274
if entry.IsRegular() && entry.Name() == target {
7375
return entry, nil
7476
}
7577
}
78+
// Then the unescaped, shortest alternative
79+
var unescapedTarget string
80+
if unescapedTarget, err = url.QueryUnescape(target); err != nil {
81+
return nil, err
82+
}
83+
for _, entry := range entries {
84+
if entry.IsRegular() && entry.Name() == unescapedTarget {
85+
return entry, nil
86+
}
87+
}
7688
return nil, nil
7789
}
7890

0 commit comments

Comments
 (0)