summaryrefslogtreecommitdiffstats
path: root/services/wiki
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2021-07-20 15:16:20 +0200
committerGitHub <noreply@github.com>2021-07-20 15:16:20 +0200
commitb26c3b482feb57704aa399d8d72a959ce667b879 (patch)
tree1984bacf320a1d4b8516807d5afe138d8842dd7e /services/wiki
parent263577842563a8a692212f897bec685751c78f23 (diff)
downloadgitea-b26c3b482feb57704aa399d8d72a959ce667b879.tar.gz
gitea-b26c3b482feb57704aa399d8d72a959ce667b879.zip
Add TestPrepareWikiFileName (#16487)
* Add TestPrepareWikiFileName * use LsTree as LsFiles is index only * ajust other tests Co-authored-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'services/wiki')
-rw-r--r--services/wiki/wiki.go2
-rw-r--r--services/wiki/wiki_test.go51
2 files changed, 52 insertions, 1 deletions
diff --git a/services/wiki/wiki.go b/services/wiki/wiki.go
index 94f36ea2f2..f1632c6bf7 100644
--- a/services/wiki/wiki.go
+++ b/services/wiki/wiki.go
@@ -88,7 +88,7 @@ func prepareWikiFileName(gitRepo *git.Repository, wikiName string) (bool, string
escaped := NameToFilename(wikiName)
// Look for both files
- filesInIndex, err := gitRepo.LsFiles(unescaped, escaped)
+ filesInIndex, err := gitRepo.LsTree("master", unescaped, escaped)
if err != nil {
log.Error("%v", err)
return false, escaped, err
diff --git a/services/wiki/wiki_test.go b/services/wiki/wiki_test.go
index b35b86d655..a1614b509c 100644
--- a/services/wiki/wiki_test.go
+++ b/services/wiki/wiki_test.go
@@ -210,3 +210,54 @@ func TestRepository_DeleteWikiPage(t *testing.T) {
_, err = masterTree.GetTreeEntryByPath(wikiPath)
assert.Error(t, err)
}
+
+func TestPrepareWikiFileName(t *testing.T) {
+ models.PrepareTestEnv(t)
+ repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ gitRepo, err := git.OpenRepository(repo.WikiPath())
+ defer gitRepo.Close()
+ assert.NoError(t, err)
+
+ tests := []struct {
+ name string
+ arg string
+ existence bool
+ wikiPath string
+ wantErr bool
+ }{{
+ name: "add suffix",
+ arg: "Home",
+ existence: true,
+ wikiPath: "Home.md",
+ wantErr: false,
+ }, {
+ name: "test special chars",
+ arg: "home of and & or wiki page!",
+ existence: false,
+ wikiPath: "home-of-and-%26-or-wiki-page%21.md",
+ wantErr: false,
+ }, {
+ name: "fount unescaped cases",
+ arg: "Unescaped File",
+ existence: true,
+ wikiPath: "Unescaped File.md",
+ wantErr: false,
+ }}
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ existence, newWikiPath, err := prepareWikiFileName(gitRepo, tt.arg)
+ if (err != nil) != tt.wantErr {
+ assert.NoError(t, err)
+ return
+ }
+ if existence != tt.existence {
+ if existence {
+ t.Errorf("expect to find no escaped file but we detect one")
+ } else {
+ t.Errorf("expect to find an escaped file but we could not detect one")
+ }
+ }
+ assert.Equal(t, tt.wikiPath, newWikiPath)
+ })
+ }
+}