@@ -22,15 +22,16 @@ import (
22
22
// - "/wiki/100%25+Free"
23
23
// - "/wiki/2000-01-02+meeting.-"
24
24
// - 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.
26
26
// * Git Path (only space doesn't need to be escaped):
27
27
// - "/.wiki.git/Home-Page.md"
28
28
// - "/.wiki.git/100%25 Free.md"
29
29
// - "/.wiki.git/2000-01-02 meeting.-.md"
30
30
// TODO: support subdirectory in the future
31
31
//
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:
33
33
// * 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.
34
35
// * 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.
35
36
36
37
type WebPath string
@@ -91,7 +92,8 @@ func WebPathSegments(s WebPath) []string {
91
92
92
93
func WebPathToGitPath (s WebPath ) string {
93
94
if strings .HasSuffix (string (s ), ".md" ) {
94
- return string (s )
95
+ ret , _ := url .PathUnescape (string (s ))
96
+ return util .PathJoinRelX (ret )
95
97
}
96
98
97
99
a := strings .Split (string (s ), "/" )
@@ -124,7 +126,10 @@ func GitPathToWebPath(s string) (wp WebPath, err error) {
124
126
func WebPathToUserTitle (s WebPath ) (dir , display string ) {
125
127
dir = path .Dir (string (s ))
126
128
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
+ }
128
133
display , _ = unescapeSegment (display )
129
134
return dir , display
130
135
}
@@ -141,8 +146,7 @@ func WebPathFromRequest(s string) WebPath {
141
146
}
142
147
143
148
func 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.
146
150
// So we do not add the support for writing slashes in title at the moment.
147
151
title = strings .TrimSpace (title )
148
152
title = util .PathJoinRelX (base , escapeSegToWeb (title , false ))
0 commit comments