summaryrefslogtreecommitdiffstats
path: root/models/wiki.go
diff options
context:
space:
mode:
authorBwko <bouwko@gmail.com>2017-01-22 16:08:54 +0100
committerLunny Xiao <xiaolunwen@gmail.com>2017-01-22 23:08:54 +0800
commit1257d43e147efd985e740e0ec59f2e5b015e5b7d (patch)
tree81ba6ee29ffd2f16d1ee59e27ad5e1bd5db8ba14 /models/wiki.go
parentf9a3aa87370ae432a1db6a57af939bd672353156 (diff)
downloadgitea-1257d43e147efd985e740e0ec59f2e5b015e5b7d.tar.gz
gitea-1257d43e147efd985e740e0ec59f2e5b015e5b7d.zip
Add a reserved path check to the wiki (#720)
Diffstat (limited to 'models/wiki.go')
-rw-r--r--models/wiki.go19
1 files changed, 18 insertions, 1 deletions
diff --git a/models/wiki.go b/models/wiki.go
index 43ebc535f3..b20b118641 100644
--- a/models/wiki.go
+++ b/models/wiki.go
@@ -21,7 +21,10 @@ import (
"code.gitea.io/gitea/modules/sync"
)
-var wikiWorkingPool = sync.NewExclusivePool()
+var (
+ reservedWikiPaths = []string{"_pages", "_new", "_edit"}
+ wikiWorkingPool = sync.NewExclusivePool()
+)
// ToWikiPageURL formats a string to corresponding wiki URL name.
func ToWikiPageURL(name string) string {
@@ -88,8 +91,22 @@ func discardLocalWikiChanges(localPath string) error {
return discardLocalRepoBranchChanges(localPath, "master")
}
+// pathAllowed checks if a wiki path is allowed
+func pathAllowed(path string) error {
+ for i := range reservedWikiPaths {
+ if path == reservedWikiPaths[i] {
+ return ErrWikiAlreadyExist{path}
+ }
+ }
+ return nil
+}
+
// updateWikiPage adds new page to repository wiki.
func (repo *Repository) updateWikiPage(doer *User, oldWikiPath, wikiPath, content, message string, isNew bool) (err error) {
+ if err = pathAllowed(wikiPath); err != nil {
+ return err
+ }
+
wikiWorkingPool.CheckIn(com.ToStr(repo.ID))
defer wikiWorkingPool.CheckOut(com.ToStr(repo.ID))