urlencode all page names - fixes non-url-safe characters in article titles
This commit is contained in:
parent
4bcc7f5dfa
commit
55796153b3
@ -83,7 +83,12 @@ func (this *WikiServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
|
||||
} else if strings.HasPrefix(r.URL.Path, this.opts.ExpectBaseURL+"view/") {
|
||||
articleTitle := r.URL.Path[len(this.opts.ExpectBaseURL+"view/"):]
|
||||
articleTitle, err := url.QueryUnescape(r.URL.Path[len(this.opts.ExpectBaseURL+"view/"):])
|
||||
if err != nil {
|
||||
this.serveErrorMessage(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
a, err := this.db.GetLatestVersion(articleTitle)
|
||||
if err != nil {
|
||||
this.serveErrorMessage(w, err)
|
||||
|
@ -3,6 +3,7 @@ package yatwiki3
|
||||
import (
|
||||
"encoding/json"
|
||||
"html/template"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
@ -44,10 +45,10 @@ func (this *BBCodeRenderer) bbcode(data string) string {
|
||||
pregReplaceRule{regexp.MustCompile(`(?si)\[\*\]`), `</li><li>`, nil},
|
||||
pregReplaceRule{regexp.MustCompile(`(?si)\[url=(.*?)\](.*?)\[/url\]`), `<a rel="noreferrer" href="$1">$2</a>`, nil},
|
||||
pregReplaceRule{regexp.MustCompile(`(?si)\[article=(.*?)\](.*?)\[/article\]`), "", func(m []string) string {
|
||||
return `<a href="` + this.baseUrl + `view/` + template.HTMLEscapeString(m[1]) + `">` + m[2] + `</a>`
|
||||
return `<a href="` + template.HTMLEscapeString(this.baseUrl+`view/`+url.QueryEscape(m[1])) + `">` + m[2] + `</a>`
|
||||
}},
|
||||
pregReplaceRule{regexp.MustCompile(`(?si)\[rev=(.*?)\](.*?)\[/rev\]`), "", func(m []string) string {
|
||||
return `<a href="` + this.baseUrl + `archive/` + template.HTMLEscapeString(m[1]) + `">` + m[2] + `</a>`
|
||||
return `<a href="` + template.HTMLEscapeString(this.baseUrl+`archive/`+url.QueryEscape(m[1])) + `">` + m[2] + `</a>`
|
||||
}},
|
||||
|
||||
pregReplaceRule{regexp.MustCompile(`(?si)\[imgur\](.*?)\.(...)\[/imgur\]`),
|
||||
|
@ -85,13 +85,13 @@ function els(e,s){ // no js exec in innerHTML
|
||||
</head>
|
||||
<body>
|
||||
<div class="header">
|
||||
<a href="{{.BaseURL}}view/{{.DefaultPage}}" title="Home"><div class="sprite hm"></div></a>
|
||||
<a href="{{.BaseURL}}view/{{.DefaultPage | urlquery}}" title="Home"><div class="sprite hm"></div></a>
|
||||
<a href="javascript:;" onclick="tid('spm');tid('tr1');tid('tr2');" title="Menu"><div class="sprite sp"></div></a>
|
||||
<a href="{{.BaseURL}}modify/{{.NewArticleTitle}}" title="New Page"><div class="sprite nw"></div></a>
|
||||
<a href="{{.BaseURL}}modify/{{.NewArticleTitle | urlquery}}" title="New Page"><div class="sprite nw"></div></a>
|
||||
{{if .CurrentPageIsArticle }}
|
||||
<div class="sep"></div>
|
||||
<a href="{{.BaseURL}}history/{{.CurrentPageName}}" title="Page History"><div class="sprite hs"></div></a>
|
||||
<a href="{{.BaseURL}}modify/{{.CurrentPageName}}" title="Modify Page"><div class="sprite ed"></div></a>
|
||||
<a href="{{.BaseURL}}history/{{.CurrentPageName | urlquery}}" title="Page History"><div class="sprite hs"></div></a>
|
||||
<a href="{{.BaseURL}}modify/{{.CurrentPageName | urlquery}}" title="Modify Page"><div class="sprite ed"></div></a>
|
||||
{{end}}
|
||||
</div>
|
||||
<div id="tr1" style="display:none;"></div>
|
||||
|
Loading…
Reference in New Issue
Block a user