summaryrefslogtreecommitdiffstats
path: root/routers/repo/wiki.go
diff options
context:
space:
mode:
authorGabriel Silva Simões <simoes.sgabriel@gmail.com>2019-02-05 20:58:55 -0500
committertechknowlogick <matti@mdranta.net>2019-02-05 20:58:55 -0500
commit3b7f41f9f7bbd3d19ce5a6b667b5c1f56c2b1b51 (patch)
tree02faf1bad6fce7f2b4357e7a4c705c6f8069fd23 /routers/repo/wiki.go
parent4a747aef7b24970a199f246c22974f7e1ba31382 (diff)
downloadgitea-3b7f41f9f7bbd3d19ce5a6b667b5c1f56c2b1b51.tar.gz
gitea-3b7f41f9f7bbd3d19ce5a6b667b5c1f56c2b1b51.zip
Fix serving of raw wiki files other than .md (#5814)
* Fix serving of raw wiki files other than .md Closes #4690. Closes #4395. Signed-off-by: Gabriel Silva Simões <simoes.sgabriel@gmail.com> * Simplify code at routers/repo/wiki.go Signed-off-by: Gabriel Silva Simões <simoes.sgabriel@gmail.com> * Add more files to user2/repo1.wiki for testing Signed-off-by: Gabriel Silva Simões <simoes.sgabriel@gmail.com> * Update macaron to v1.3.2 Signed-off-by: Gabriel Silva Simões <simoes.sgabriel@gmail.com> * Add tests for WikiRaw Signed-off-by: Gabriel Silva Simões <simoes.sgabriel@gmail.com> * Fix NewResponseWriter usage due to macaron update Signed-off-by: Gabriel Silva Simões <simoes.sgabriel@gmail.com> * Add raw to reserved wiki names Signed-off-by: Gabriel Silva Simões <simoes.sgabriel@gmail.com>
Diffstat (limited to 'routers/repo/wiki.go')
-rw-r--r--routers/repo/wiki.go41
1 files changed, 28 insertions, 13 deletions
diff --git a/routers/repo/wiki.go b/routers/repo/wiki.go
index 6a25d9ffea..8426406c31 100644
--- a/routers/repo/wiki.go
+++ b/routers/repo/wiki.go
@@ -295,26 +295,41 @@ func WikiRaw(ctx *context.Context) {
return
}
}
+
providedPath := ctx.Params("*")
- if strings.HasSuffix(providedPath, ".md") {
- providedPath = providedPath[:len(providedPath)-3]
- }
- wikiPath := models.WikiNameToFilename(providedPath)
+
var entry *git.TreeEntry
if commit != nil {
- entry, err = findEntryForFile(commit, wikiPath)
+ // Try to find a file with that name
+ entry, err = findEntryForFile(commit, providedPath)
+ if err != nil {
+ ctx.ServerError("findFile", err)
+ return
+ }
+
+ if entry == nil {
+ // Try to find a wiki page with that name
+ if strings.HasSuffix(providedPath, ".md") {
+ providedPath = providedPath[:len(providedPath)-3]
+ }
+
+ wikiPath := models.WikiNameToFilename(providedPath)
+ entry, err = findEntryForFile(commit, wikiPath)
+ if err != nil {
+ ctx.ServerError("findFile", err)
+ return
+ }
+ }
}
- if err != nil {
- ctx.ServerError("findFile", err)
- return
- } else if entry == nil {
- ctx.NotFound("findEntryForFile", nil)
+
+ if entry != nil {
+ if err = ServeBlob(ctx, entry.Blob()); err != nil {
+ ctx.ServerError("ServeBlob", err)
+ }
return
}
- if err = ServeBlob(ctx, entry.Blob()); err != nil {
- ctx.ServerError("ServeBlob", err)
- }
+ ctx.NotFound("findEntryForFile", nil)
}
// NewWiki render wiki create page