Skip to content

Add a reserved wiki paths check to the wiki #720

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

Merged
merged 1 commit into from
Jan 22, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion models/wiki.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import (
"code.gitea.io/gitea/modules/sync"
)

var wikiWorkingPool = sync.NewExclusivePool()
var (
reservedUncycloPaths = []string{"_pages", "_new", "_edit"}
wikiWorkingPool = sync.NewExclusivePool()
)

// ToUncycloPageURL formats a string to corresponding wiki URL name.
func ToUncycloPageURL(name string) string {
Expand Down Expand Up @@ -88,8 +91,22 @@ func discardLocalUncycloChanges(localPath string) error {
return discardLocalRepoBranchChanges(localPath, "master")
}

// pathAllowed checks if a wiki path is allowed
func pathAllowed(path string) error {
for i := range reservedUncycloPaths {
if path == reservedUncycloPaths[i] {
return ErrUncycloAlreadyExist{path}
}
}
return nil
}

// updateUncycloPage adds new page to repository wiki.
func (repo *Repository) updateUncycloPage(doer *User, oldUncycloPath, 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))

Expand Down