@@ -22,15 +22,16 @@ 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"
2929// - "/.wiki.git/2000-01-02 meeting.-.md"
3030// TODO: support subdirectory in the future
3131//
32- // Although this package now has the ablity to support subdirectory, but the route package doesn't:
32+ // Although this package now has the ability to support subdirectory, but the route package doesn't:
3333// * Double-escaping problem: the URL "/wiki/abc%2Fdef" becomes "/wiki/abc/def" by ctx.Params, which is incorrect
34+ // * This problem should have been 99% fixed, but it needs more tests.
3435// * The old wiki code's behavior is always using %2F, instead of subdirectory, so there are a lot of legacy "%2F" files in user wikis.
3536
3637type WebPath string
@@ -91,7 +92,8 @@ func WebPathSegments(s WebPath) []string {
9192
9293func WebPathToGitPath (s WebPath ) string {
9394 if strings .HasSuffix (string (s ), ".md" ) {
94- return string (s )
95+ ret , _ := url .PathUnescape (string (s ))
96+ return util .PathJoinRelX (ret )
9597 }
9698
9799 a := strings .Split (string (s ), "/" )
@@ -124,7 +126,10 @@ func GitPathToWebPath(s string) (wp WebPath, err error) {
124126func WebPathToUserTitle (s WebPath ) (dir , display string ) {
125127 dir = path .Dir (string (s ))
126128 display = path .Base (string (s ))
127- display = strings .TrimSuffix (display , ".md" )
129+ if strings .HasSuffix (display , ".md" ) {
130+ display = strings .TrimSuffix (display , ".md" )
131+ display , _ = url .PathUnescape (display )
132+ }
128133 display , _ = unescapeSegment (display )
129134 return dir , display
130135}
@@ -141,8 +146,7 @@ func WebPathFromRequest(s string) WebPath {
141146}
142147
143148func 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.
149+ // TODO: no support for subdirectory, because the old wiki code's behavior is always using %2F, instead of subdirectory.
146150 // So we do not add the support for writing slashes in title at the moment.
147151 title = strings .TrimSpace (title )
148152 title = util .PathJoinRelX (base , escapeSegToWeb (title , false ))
0 commit comments