Skip to content

Commit 1590bd5

Browse files
committed
enforce wiki roots start with /
1 parent e7fb263 commit 1590bd5

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

wikifier/page-opt.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,11 @@ func InjectPageOpt(page *Page, opt *PageOpt) error {
227227
opt.Dir.Category = filepath.Join(opt.Dir.Wiki, "cache", "category")
228228

229229
// convert all HTTP roots to /
230-
opt.Root.Wiki = filepath.ToSlash(opt.Root.Wiki)
231-
opt.Root.Image = filepath.ToSlash(opt.Root.Image)
232-
opt.Root.Category = filepath.ToSlash(opt.Root.Category)
233-
opt.Root.Page = filepath.ToSlash(opt.Root.Page)
234-
opt.Root.File = filepath.ToSlash(opt.Root.File)
230+
opt.Root.Wiki = startWithSlash(filepath.ToSlash(opt.Root.Wiki))
231+
opt.Root.Image = startWithSlash(filepath.ToSlash(opt.Root.Image))
232+
opt.Root.Category = startWithSlash(filepath.ToSlash(opt.Root.Category))
233+
opt.Root.Page = startWithSlash(filepath.ToSlash(opt.Root.Page))
234+
opt.Root.File = startWithSlash(filepath.ToSlash(opt.Root.File))
235235

236236
// easy bool options
237237
pageOptBool := map[string]*bool{
@@ -329,3 +329,10 @@ func InjectPageOpt(page *Page, opt *PageOpt) error {
329329

330330
return nil
331331
}
332+
333+
func startWithSlash(s string) string {
334+
if s == "" || s[0] == '/' {
335+
return s
336+
}
337+
return "/" + s
338+
}

0 commit comments

Comments
 (0)