-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Gitea wiki repo uses urlencoded file name when creating new pages online #16122
Comments
This is indeed a problem. |
While I try to write a patch for this issue, I found there is a bug related to this issue. If you created a non-urlencoded markdown file and push it to the wiki repo, the file name can be displayed correctly, but if you edit that page online and save it with the save button, it will create a new page with urlencoded file name, and the old non-urlencoded file will still exist. My patch is here but I haven't tested it due to some other issue I've got, anyway here is the patch. be aware it's NOT TESTED diff --git a/services/wiki/wiki.go b/services/wiki/wiki.go
index 75b9d1d1f..dbf2771b3 100644
--- a/services/wiki/wiki.go
+++ b/services/wiki/wiki.go
@@ -44,6 +44,11 @@ func NormalizeWikiName(name string) string {
}
// NameToFilename converts a wiki name to its corresponding filename.
+func NameToUnescapedFilename(name string) string {
+ name = strings.ReplaceAll(name, " ", "-")
+ return name + ".md"
+}
+
func NameToFilename(name string) string {
name = strings.ReplaceAll(name, " ", "-")
return url.QueryEscape(name) + ".md"
@@ -81,6 +86,19 @@ func InitWiki(repo *models.Repository) error {
return nil
}
+func CheckFileExistence(gitRepo *git.Repository, filePath string) (bool, error) {
+ filesInIndex, err := gitRepo.LsFiles(filePath)
+ if err != nil {
+ log.Error("%v", err)
+ return false, err
+ }
+ if util.IsStringInSlice(filePath, filesInIndex) {
+ return true, nil
+ }
+
+ return false, nil
+}
+
// updateWikiPage adds a new page to the repository wiki.
func updateWikiPage(doer *models.User, repo *models.Repository, oldWikiName, newWikiName, content, message string, isNew bool) (err error) {
if err = nameAllowed(newWikiName); err != nil {
@@ -133,27 +151,40 @@ func updateWikiPage(doer *models.User, repo *models.Repository, oldWikiName, new
}
}
- newWikiPath := NameToFilename(newWikiName)
+ newWikiPath := NameToUnescapedFilename(newWikiName)
+ isWikiExist, err := CheckFileExistence(gitRepo, newWikiName)
+ if err != nil {
+ return err
+ }
+ if !isWikiExist {
+ newWikiPath = NameToFilename(newWikiName)
+ }
+
if isNew {
- filesInIndex, err := gitRepo.LsFiles(newWikiPath)
+ isNewWikiExist, err := CheckFileExistence(gitRepo, newWikiPath)
if err != nil {
- log.Error("%v", err)
return err
}
- if util.IsStringInSlice(newWikiPath, filesInIndex) {
+ if isNewWikiExist {
return models.ErrWikiAlreadyExist{
Title: newWikiPath,
}
}
} else {
- oldWikiPath := NameToFilename(oldWikiName)
- filesInIndex, err := gitRepo.LsFiles(oldWikiPath)
+ oldWikiPath := NameToUnescapedFilename(oldWikiName)
+ isOldWikiExist, err := CheckFileExistence(gitRepo, newWikiName)
if err != nil {
- log.Error("%v", err)
return err
}
+ if !isOldWikiExist {
+ oldWikiPath = NameToFilename(newWikiName)
+ isOldWikiExist, err = CheckFileExistence(gitRepo, newWikiName)
+ if err != nil {
+ return err
+ }
+ }
- if util.IsStringInSlice(oldWikiPath, filesInIndex) {
+ if isOldWikiExist {
err := gitRepo.RemoveFilesFromIndex(oldWikiPath)
if err != nil {
log.Error("%v", err)
This patch will try to find if there is a non-urlencoded file in the repo and try to update that file if there is, which may fixes the bug mention in this comment. This will of course not fix the main issue since it will not try to use the wiki page name as-is as the newly created file name. Using the page name as-is by default may probably break already existed wikis so I'm not sure about the right way to do it. Edit: the patch in this comment is not correct, a patch tested on my laptop is sent via PR, see #16139 |
I updated the description to match the main point of this issue. While working on the third issue (wiki page contains space cannot be viewed from the Gitea wiki webpage), I found it seems harder to fix. I cannot find a way to fix this issue and also keep the old behavior not break. Any suggestions? To help others reproduce that issue, you can:
|
I tested GitHub Wiki's behavior for reference: When creating wiki page online (with Markdown chose as its format):
Space( When creating wiki page locally, then commit and push it to wiki repo:
Page URL seems weird but the page title can still be displayed correctly. When editing a non-regular naming page, let's assume there is a file names |
Some additional tests: Create
BTW, I don't think GitHub Wiki dees are good since users won't be able to use some characters in a wiki title which can be confused. A page with title names |
Description
When creating a new wiki page online, it will generate a urlencoded file name for that page to the wiki repo, instead of using the page title as-is, which can make local management (i.e. clone the wiki repo locally and use it as a regular git repo to manage documentation or notes) vary hard.
Not sure if that's intended, but for reference, GitHub, instead, will (at least try to) use the wiki page title as-is as the name of the new file.
List of related issues that need to be discussed/fixed
Test Test.md
)/
character?The text was updated successfully, but these errors were encountered: