summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorTekaoh <45337851+Tekaoh@users.noreply.github.com>2019-10-09 13:49:37 -0500
committerLauris BH <lauris@nix.lv>2019-10-09 21:49:37 +0300
commitb6616591d190da56ba1ce06570f38a6cca3821d6 (patch)
treebb0e47a1b93ad073f99aa5ee62852300a085747b /routers
parent7ad46cc116e4749a0d45572f1a8c53d0c8729080 (diff)
downloadgitea-b6616591d190da56ba1ce06570f38a6cca3821d6.tar.gz
gitea-b6616591d190da56ba1ce06570f38a6cca3821d6.zip
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>
Diffstat (limited to 'routers')
-rw-r--r--routers/repo/wiki.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/routers/repo/wiki.go b/routers/repo/wiki.go
index bf8ac658ae..02fbe4a1dd 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
}