aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2020-01-28 23:10:40 +0800
committerzeripath <art27@cantab.net>2020-01-28 15:10:40 +0000
commit158b7163872e900984b4fd64e81a8a316e281bc8 (patch)
tree84ebd3ab7cbfb63ba602c367d67c44e4e7acfdd3
parente611dbbe866819bc2f933589e208f9a95ad0a9d1 (diff)
downloadgitea-158b7163872e900984b4fd64e81a8a316e281bc8.tar.gz
gitea-158b7163872e900984b4fd64e81a8a316e281bc8.zip
Fix wiki raw view on sub path (#10002) (#10041)
* Fix wiki raw view on sub path * Add test for subpath wiki raw file * Fix bug Co-authored-by: zeripath <art27@cantab.net>
-rw-r--r--integrations/gitea-repositories-meta/user2/repo1.wiki.git/objects/42/3313fbd38093bb10d0c8387db9105409c6f196bin0 -> 830 bytes
-rw-r--r--integrations/gitea-repositories-meta/user2/repo1.wiki.git/objects/74/d5a0d73db9b9ef7aa9978eb7a099b08f54d45ebin0 -> 53 bytes
-rw-r--r--integrations/gitea-repositories-meta/user2/repo1.wiki.git/objects/c4/b38c3e1395393f75bbbc2ed10c7eeb577d3b64bin0 -> 189 bytes
-rw-r--r--integrations/gitea-repositories-meta/user2/repo1.wiki.git/refs/heads/master2
-rw-r--r--routers/repo/wiki.go28
-rw-r--r--routers/repo/wiki_test.go1
6 files changed, 12 insertions, 19 deletions
diff --git a/integrations/gitea-repositories-meta/user2/repo1.wiki.git/objects/42/3313fbd38093bb10d0c8387db9105409c6f196 b/integrations/gitea-repositories-meta/user2/repo1.wiki.git/objects/42/3313fbd38093bb10d0c8387db9105409c6f196
new file mode 100644
index 0000000000..bf4ae859f6
--- /dev/null
+++ b/integrations/gitea-repositories-meta/user2/repo1.wiki.git/objects/42/3313fbd38093bb10d0c8387db9105409c6f196
Binary files differ
diff --git a/integrations/gitea-repositories-meta/user2/repo1.wiki.git/objects/74/d5a0d73db9b9ef7aa9978eb7a099b08f54d45e b/integrations/gitea-repositories-meta/user2/repo1.wiki.git/objects/74/d5a0d73db9b9ef7aa9978eb7a099b08f54d45e
new file mode 100644
index 0000000000..bcb0e0075c
--- /dev/null
+++ b/integrations/gitea-repositories-meta/user2/repo1.wiki.git/objects/74/d5a0d73db9b9ef7aa9978eb7a099b08f54d45e
Binary files differ
diff --git a/integrations/gitea-repositories-meta/user2/repo1.wiki.git/objects/c4/b38c3e1395393f75bbbc2ed10c7eeb577d3b64 b/integrations/gitea-repositories-meta/user2/repo1.wiki.git/objects/c4/b38c3e1395393f75bbbc2ed10c7eeb577d3b64
new file mode 100644
index 0000000000..6dcfc96676
--- /dev/null
+++ b/integrations/gitea-repositories-meta/user2/repo1.wiki.git/objects/c4/b38c3e1395393f75bbbc2ed10c7eeb577d3b64
Binary files differ
diff --git a/integrations/gitea-repositories-meta/user2/repo1.wiki.git/refs/heads/master b/integrations/gitea-repositories-meta/user2/repo1.wiki.git/refs/heads/master
index 86de6490a2..1b1d96a1f0 100644
--- a/integrations/gitea-repositories-meta/user2/repo1.wiki.git/refs/heads/master
+++ b/integrations/gitea-repositories-meta/user2/repo1.wiki.git/refs/heads/master
@@ -1 +1 @@
-0cf15c3f66ec8384480ed9c3cf87c9e97fbb0ec3
+423313fbd38093bb10d0c8387db9105409c6f196
diff --git a/routers/repo/wiki.go b/routers/repo/wiki.go
index 6cf1943658..bd68473bf4 100644
--- a/routers/repo/wiki.go
+++ b/routers/repo/wiki.go
@@ -65,27 +65,20 @@ type PageMeta struct {
// findEntryForFile finds the tree entry for a target filepath.
func findEntryForFile(commit *git.Commit, target string) (*git.TreeEntry, error) {
- entries, err := commit.ListEntries()
- if err != nil {
+ entry, err := commit.GetTreeEntryByPath(target)
+ if err != nil && !git.IsErrNotExist(err) {
return nil, err
}
- // The longest name should be checked first
- for _, entry := range entries {
- if entry.IsRegular() && entry.Name() == target {
- return entry, nil
- }
+ if entry != nil {
+ 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
+ return commit.GetTreeEntryByPath(unescapedTarget)
}
func findWikiRepoCommit(ctx *context.Context) (*git.Repository, *git.Commit, error) {
@@ -122,10 +115,9 @@ func wikiContentsByEntry(ctx *context.Context, entry *git.TreeEntry) []byte {
// wikiContentsByName returns the contents of a wiki page, along with a boolean
// indicating whether the page exists. Writes to ctx if an error occurs.
func wikiContentsByName(ctx *context.Context, commit *git.Commit, wikiName string) ([]byte, *git.TreeEntry, string, bool) {
- var entry *git.TreeEntry
- var err error
pageFilename := models.WikiNameToFilename(wikiName)
- if entry, err = findEntryForFile(commit, pageFilename); err != nil {
+ entry, err := findEntryForFile(commit, pageFilename)
+ if err != nil && !git.IsErrNotExist(err) {
ctx.ServerError("findEntryForFile", err)
return nil, nil, "", false
} else if entry == nil {
@@ -517,7 +509,7 @@ func WikiRaw(ctx *context.Context) {
if commit != nil {
// Try to find a file with that name
entry, err = findEntryForFile(commit, providedPath)
- if err != nil {
+ if err != nil && !git.IsErrNotExist(err) {
ctx.ServerError("findFile", err)
return
}
@@ -530,7 +522,7 @@ func WikiRaw(ctx *context.Context) {
wikiPath := models.WikiNameToFilename(providedPath)
entry, err = findEntryForFile(commit, wikiPath)
- if err != nil {
+ if err != nil && !git.IsErrNotExist(err) {
ctx.ServerError("findFile", err)
return
}
diff --git a/routers/repo/wiki_test.go b/routers/repo/wiki_test.go
index 44fcd02035..50a2500a01 100644
--- a/routers/repo/wiki_test.go
+++ b/routers/repo/wiki_test.go
@@ -191,6 +191,7 @@ func TestDeleteWikiPagePost(t *testing.T) {
func TestWikiRaw(t *testing.T) {
for filepath, filetype := range map[string]string{
"jpeg.jpg": "image/jpeg",
+ "images/jpeg.jpg": "image/jpeg",
"Page With Spaced Name": "text/plain; charset=utf-8",
"Page-With-Spaced-Name": "text/plain; charset=utf-8",
"Page With Spaced Name.md": "text/plain; charset=utf-8",