diff --git a/Gopkg.lock b/Gopkg.lock index 0df0cf57d..8eb150bc9 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -1108,12 +1108,12 @@ version = "v2.5.1" [[projects]] - digest = "1:cfe1730a152ff033ad7d9c115d22e36b19eec6d5928c06146b9119be45d39dc0" + digest = "1:de2e7294c9bd0b7d07ada8e98ad02cbbaabacff90eedebe7454ebdbab50d0d19" name = "gopkg.in/macaron.v1" packages = ["."] pruneopts = "NUT" - revision = "75f2e9b42e99652f0d82b28ccb73648f44615faa" - version = "v1.2.4" + revision = "dfcb80ca86e8534962c62812efd93209c7e600e7" + version = "v1.3.2" [[projects]] digest = "1:00126f697efdcab42f07c89ac8bf0095fb2328aef6464e070055154088cea859" diff --git a/integrations/gitea-repositories-meta/user2/repo1.wiki.git/objects/0c/f15c3f66ec8384480ed9c3cf87c9e97fbb0ec3 b/integrations/gitea-repositories-meta/user2/repo1.wiki.git/objects/0c/f15c3f66ec8384480ed9c3cf87c9e97fbb0ec3 new file mode 100644 index 000000000..c0314c558 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/repo1.wiki.git/objects/0c/f15c3f66ec8384480ed9c3cf87c9e97fbb0ec3 @@ -0,0 +1,2 @@ +xm DMY(J`5ɜ-K*Ki,Hi!?K_sq/]09MHpѤk_d-%풇۞ v_]^/I[t \ No newline at end of file diff --git a/integrations/gitea-repositories-meta/user2/repo1.wiki.git/objects/32/5dc4f8e9344e6668f21536a69d5f1d4ed53ca3 b/integrations/gitea-repositories-meta/user2/repo1.wiki.git/objects/32/5dc4f8e9344e6668f21536a69d5f1d4ed53ca3 new file mode 100644 index 000000000..d52aa8e1f Binary files /dev/null and b/integrations/gitea-repositories-meta/user2/repo1.wiki.git/objects/32/5dc4f8e9344e6668f21536a69d5f1d4ed53ca3 differ diff --git a/integrations/gitea-repositories-meta/user2/repo1.wiki.git/objects/71/911bf48766c7181518c1070911019fbb00b1fc b/integrations/gitea-repositories-meta/user2/repo1.wiki.git/objects/71/911bf48766c7181518c1070911019fbb00b1fc new file mode 100644 index 000000000..84ade8198 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/repo1.wiki.git/objects/71/911bf48766c7181518c1070911019fbb00b1fc @@ -0,0 +1 @@ +xM@ Mr›6&&&9Leśwt<#͡mv-0wbjy̖ڗ~݋[=H ."ǁ= \ No newline at end of file diff --git a/integrations/gitea-repositories-meta/user2/repo1.wiki.git/objects/72/fc6251cc648e914c10009d31431fa2e38b9a20 b/integrations/gitea-repositories-meta/user2/repo1.wiki.git/objects/72/fc6251cc648e914c10009d31431fa2e38b9a20 new file mode 100644 index 000000000..052fdf35a Binary files /dev/null and b/integrations/gitea-repositories-meta/user2/repo1.wiki.git/objects/72/fc6251cc648e914c10009d31431fa2e38b9a20 differ diff --git a/integrations/gitea-repositories-meta/user2/repo1.wiki.git/objects/7c/d7c8fa852973c72c66eb120a6677c54a8697f7 b/integrations/gitea-repositories-meta/user2/repo1.wiki.git/objects/7c/d7c8fa852973c72c66eb120a6677c54a8697f7 new file mode 100644 index 000000000..9c2649560 Binary files /dev/null and b/integrations/gitea-repositories-meta/user2/repo1.wiki.git/objects/7c/d7c8fa852973c72c66eb120a6677c54a8697f7 differ diff --git a/integrations/gitea-repositories-meta/user2/repo1.wiki.git/objects/c1/0d10b7e655b3dab1f53176db57c8219a5488d6 b/integrations/gitea-repositories-meta/user2/repo1.wiki.git/objects/c1/0d10b7e655b3dab1f53176db57c8219a5488d6 new file mode 100644 index 000000000..8a6345dfa --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/repo1.wiki.git/objects/c1/0d10b7e655b3dab1f53176db57c8219a5488d6 @@ -0,0 +1,2 @@ +xm0)nt2S`ņe,VY/H#[)E@Nq툎r2)D0jCLaC&4Bv]$EIӑePrIsez˳~_ +[yvWV=헛˘H vZ~s@݉%?TZH \ No newline at end of file diff --git a/integrations/gitea-repositories-meta/user2/repo1.wiki.git/objects/f5/05ec9b5c7a45a10259c1dda7f18434e5d55940 b/integrations/gitea-repositories-meta/user2/repo1.wiki.git/objects/f5/05ec9b5c7a45a10259c1dda7f18434e5d55940 new file mode 100644 index 000000000..eaeadaeae Binary files /dev/null and b/integrations/gitea-repositories-meta/user2/repo1.wiki.git/objects/f5/05ec9b5c7a45a10259c1dda7f18434e5d55940 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 b22bbf31f..86de6490a 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 @@ -2c54faec6c45d31c1abfaecdab471eac6633738a +0cf15c3f66ec8384480ed9c3cf87c9e97fbb0ec3 diff --git a/models/wiki.go b/models/wiki.go index d61593609..65cf26a44 100644 --- a/models/wiki.go +++ b/models/wiki.go @@ -22,7 +22,7 @@ import ( ) var ( - reservedWikiNames = []string{"_pages", "_new", "_edit"} + reservedWikiNames = []string{"_pages", "_new", "_edit", "raw"} wikiWorkingPool = sync.NewExclusivePool() ) diff --git a/routers/api/v1/misc/markdown_test.go b/routers/api/v1/misc/markdown_test.go index f9503bc63..32d2f0730 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 6a25d9ffe..8426406c3 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 d433a8629..99812cab4 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")) + } +} diff --git a/vendor/gopkg.in/macaron.v1/context.go b/vendor/gopkg.in/macaron.v1/context.go index 94a8c45d7..063f9e014 100644 --- a/vendor/gopkg.in/macaron.v1/context.go +++ b/vendor/gopkg.in/macaron.v1/context.go @@ -262,7 +262,7 @@ func (ctx *Context) Params(name string) string { // SetParams sets value of param with given name. func (ctx *Context) SetParams(name, val string) { - if !strings.HasPrefix(name, ":") { + if name != "*" && !strings.HasPrefix(name, ":") { name = ":" + name } ctx.params[name] = val @@ -270,7 +270,7 @@ func (ctx *Context) SetParams(name, val string) { // ReplaceAllParams replace all current params with given params func (ctx *Context) ReplaceAllParams(params Params) { - ctx.params = params; + ctx.params = params } // ParamsEscape returns escapred params result. diff --git a/vendor/gopkg.in/macaron.v1/macaron.go b/vendor/gopkg.in/macaron.v1/macaron.go index 5926e6136..715076ac1 100644 --- a/vendor/gopkg.in/macaron.v1/macaron.go +++ b/vendor/gopkg.in/macaron.v1/macaron.go @@ -32,7 +32,7 @@ import ( "github.com/go-macaron/inject" ) -const _VERSION = "1.2.4.1123" +const _VERSION = "1.3.2.1216" func Version() string { return _VERSION @@ -194,7 +194,7 @@ func (m *Macaron) createContext(rw http.ResponseWriter, req *http.Request) *Cont index: 0, Router: m.Router, Req: Request{req}, - Resp: NewResponseWriter(rw), + Resp: NewResponseWriter(req.Method, rw), Render: &DummyRender{rw}, Data: make(map[string]interface{}), } diff --git a/vendor/gopkg.in/macaron.v1/response_writer.go b/vendor/gopkg.in/macaron.v1/response_writer.go index ab54f56c0..9133948f9 100644 --- a/vendor/gopkg.in/macaron.v1/response_writer.go +++ b/vendor/gopkg.in/macaron.v1/response_writer.go @@ -42,11 +42,12 @@ type ResponseWriter interface { type BeforeFunc func(ResponseWriter) // NewResponseWriter creates a ResponseWriter that wraps an http.ResponseWriter -func NewResponseWriter(rw http.ResponseWriter) ResponseWriter { - return &responseWriter{rw, 0, 0, nil} +func NewResponseWriter(method string, rw http.ResponseWriter) ResponseWriter { + return &responseWriter{method, rw, 0, 0, nil} } type responseWriter struct { + method string http.ResponseWriter status int size int @@ -59,13 +60,15 @@ func (rw *responseWriter) WriteHeader(s int) { rw.status = s } -func (rw *responseWriter) Write(b []byte) (int, error) { +func (rw *responseWriter) Write(b []byte) (size int, err error) { if !rw.Written() { // The status will be StatusOK if WriteHeader has not been called yet rw.WriteHeader(http.StatusOK) } - size, err := rw.ResponseWriter.Write(b) - rw.size += size + if rw.method != "HEAD" { + size, err = rw.ResponseWriter.Write(b) + rw.size += size + } return size, err } diff --git a/vendor/gopkg.in/macaron.v1/router.go b/vendor/gopkg.in/macaron.v1/router.go index 950c5bcb0..df593d669 100644 --- a/vendor/gopkg.in/macaron.v1/router.go +++ b/vendor/gopkg.in/macaron.v1/router.go @@ -96,7 +96,7 @@ func NewRouter() *Router { } // SetAutoHead sets the value who determines whether add HEAD method automatically -// when GET method is added. Combo router will not be affected by this value. +// when GET method is added. func (r *Router) SetAutoHead(v bool) { r.autoHead = v } @@ -341,6 +341,9 @@ func (cr *ComboRouter) route(fn func(string, ...Handler) *Route, method string, } func (cr *ComboRouter) Get(h ...Handler) *ComboRouter { + if cr.router.autoHead { + cr.Head(h...) + } return cr.route(cr.router.Get, "GET", h...) }