summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/misc/markdown_test.go2
-rw-r--r--routers/repo/wiki.go41
-rw-r--r--routers/repo/wiki_test.go24
3 files changed, 51 insertions, 16 deletions
diff --git a/routers/api/v1/misc/markdown_test.go b/routers/api/v1/misc/markdown_test.go
index f9503bc639..32d2f0730e 100644
--- a/routers/api/v1/misc/markdown_test.go
+++ b/routers/api/v1/misc/markdown_test.go
@@ -27,7 +27,7 @@ func createContext(req *http.Request) (*macaron.Context, *httptest.ResponseRecor
c := &macaron.Context{
Injector: inject.New(),
Req: macaron.Request{Request: req},
- Resp: macaron.NewResponseWriter(resp),
+ Resp: macaron.NewResponseWriter(req.Method, resp),
Render: &macaron.DummyRender{ResponseWriter: resp},
Data: make(map[string]interface{}),
}
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
diff --git a/routers/repo/wiki_test.go b/routers/repo/wiki_test.go
index d433a86292..99812cab47 100644
--- a/routers/repo/wiki_test.go
+++ b/routers/repo/wiki_test.go
@@ -77,7 +77,7 @@ func TestWiki(t *testing.T) {
Wiki(ctx)
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
assert.EqualValues(t, "Home", ctx.Data["Title"])
- assertPagesMetas(t, []string{"Home"}, ctx.Data["Pages"])
+ assertPagesMetas(t, []string{"Home", "Page With Image", "Page With Spaced Name"}, ctx.Data["Pages"])
}
func TestWikiPages(t *testing.T) {
@@ -87,7 +87,7 @@ func TestWikiPages(t *testing.T) {
test.LoadRepo(t, ctx, 1)
WikiPages(ctx)
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
- assertPagesMetas(t, []string{"Home"}, ctx.Data["Pages"])
+ assertPagesMetas(t, []string{"Home", "Page With Image", "Page With Spaced Name"}, ctx.Data["Pages"])
}
func TestNewWiki(t *testing.T) {
@@ -185,3 +185,23 @@ func TestDeleteWikiPagePost(t *testing.T) {
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
assertWikiNotExists(t, ctx.Repo.Repository, "Home")
}
+
+func TestWikiRaw(t *testing.T) {
+ for filepath, filetype := range map[string]string{
+ "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",
+ "Page-With-Spaced-Name.md": "text/plain; charset=utf-8",
+ } {
+ models.PrepareTestEnv(t)
+
+ ctx := test.MockContext(t, "user2/repo1/wiki/raw/"+filepath)
+ ctx.SetParams("*", filepath)
+ test.LoadUser(t, ctx, 2)
+ test.LoadRepo(t, ctx, 1)
+ WikiRaw(ctx)
+ assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
+ assert.EqualValues(t, filetype, ctx.Resp.Header().Get("Content-Type"))
+ }
+}