@@ -22,7 +22,7 @@ import (
2222// - "/wiki/100%25+Free"
2323// - "/wiki/2000-01-02+meeting.-"
2424// - If a segment has a suffix "DashMarker(.-)", it means that there is no dash-space conversion for this segment.
25- // - If a WebPath is a "*.md" pattern, then use it directly as GitPath, to make users can access the raw file.
25+ // - If a WebPath is a "*.md" pattern, then use the unescaped value directly as GitPath, to make users can access the raw file.
2626// * Git Path (only space doesn't need to be escaped):
2727// - "/.wiki.git/Home-Page.md"
2828// - "/.wiki.git/100%25 Free.md"
@@ -91,7 +91,8 @@ func WebPathSegments(s WebPath) []string {
9191
9292func WebPathToGitPath (s WebPath ) string {
9393 if strings .HasSuffix (string (s ), ".md" ) {
94- return string (s )
94+ ret , _ := url .PathUnescape (string (s ))
95+ return util .PathJoinRelX (ret )
9596 }
9697
9798 a := strings .Split (string (s ), "/" )
@@ -124,7 +125,10 @@ func GitPathToWebPath(s string) (wp WebPath, err error) {
124125func WebPathToUserTitle (s WebPath ) (dir , display string ) {
125126 dir = path .Dir (string (s ))
126127 display = path .Base (string (s ))
127- display = strings .TrimSuffix (display , ".md" )
128+ if strings .HasSuffix (display , ".md" ) {
129+ display = strings .TrimSuffix (display , ".md" )
130+ display , _ = url .PathUnescape (display )
131+ }
128132 display , _ = unescapeSegment (display )
129133 return dir , display
130134}
@@ -141,8 +145,7 @@ func WebPathFromRequest(s string) WebPath {
141145}
142146
143147func UserTitleToWebPath (base , title string ) WebPath {
144- // TODO: ctx.Params does un-escaping, so the URL "/wiki/abc%2Fdef" becomes "wiki path = `abc/def`", which is incorrect.
145- // And the old wiki code's behavior is always using %2F, instead of subdirectory.
148+ // TODO: the old wiki code's behavior is always using %2F, instead of subdirectory.
146149 // So we do not add the support for writing slashes in title at the moment.
147150 title = strings .TrimSpace (title )
148151 title = util .PathJoinRelX (base , escapeSegToWeb (title , false ))
0 commit comments