Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix serving of raw wiki files other than .md #5814

Merged
merged 9 commits into from Feb 6, 2019
6 changes: 3 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -0,0 +1,2 @@
x���m� D�M��Y����(�J�`�5�ɜ-�K*Ki,Hi!?��<�i�Vki0Z��XH�D(Z6ĨG�Sb��3�JD�h��!�uB��DaJp� ���F�Lƹ4+~��v�;���
e����[Nx>K�����_s�q�/�]09MHpѤ��k���_d�-%�풇۞�� v�_�]��^�/�I[t
Binary file not shown.
@@ -0,0 +1 @@
x�M�@ ��M����r�›�6�&&&��9Le�św����t<#���͡�mv-��0w�b��jy̖��ڗ~݋[�����=H� �.�"������ǁ=
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,2 @@
x���m�0���)n���t2�S����`ņ���e�,VY�/H�#�[)��E��@N�q��툎�r2�)D��0�j�C���L��aC��&�4B�v]$E����Iӑe����P�r�I�s�e�z�˳~_
���[y��v��W��V=헛�˘�H vZ~s�@݉%����?T�ZH
Binary file not shown.
@@ -1 +1 @@
2c54faec6c45d31c1abfaecdab471eac6633738a
0cf15c3f66ec8384480ed9c3cf87c9e97fbb0ec3
2 changes: 1 addition & 1 deletion models/wiki.go
Expand Up @@ -22,7 +22,7 @@ import (
)

var (
reservedWikiNames = []string{"_pages", "_new", "_edit"}
reservedWikiNames = []string{"_pages", "_new", "_edit", "raw"}
zeripath marked this conversation as resolved.
Show resolved Hide resolved
wikiWorkingPool = sync.NewExclusivePool()
)

Expand Down
2 changes: 1 addition & 1 deletion routers/api/v1/misc/markdown_test.go
Expand Up @@ -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{}),
}
Expand Down
41 changes: 28 additions & 13 deletions routers/repo/wiki.go
Expand Up @@ -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
Expand Down
24 changes: 22 additions & 2 deletions routers/repo/wiki_test.go
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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"))
}
}
4 changes: 2 additions & 2 deletions vendor/gopkg.in/macaron.v1/context.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/gopkg.in/macaron.v1/macaron.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions vendor/gopkg.in/macaron.v1/response_writer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion vendor/gopkg.in/macaron.v1/router.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.