use PathEscape instead of QueryEscape for titles in URLs
This commit is contained in:
parent
c87eaa637a
commit
e515d73052
@ -128,7 +128,7 @@ func (this *WikiServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
|
|
||||||
} else if remainingPath == "" {
|
} else if remainingPath == "" {
|
||||||
this.serveRedirect(w, this.opts.ExpectBaseURL+`view/`+url.QueryEscape(this.opts.DefaultPage))
|
this.serveRedirect(w, this.opts.ExpectBaseURL+`view/`+url.PathEscape(this.opts.DefaultPage))
|
||||||
return
|
return
|
||||||
|
|
||||||
} else if remainingPath == "random" {
|
} else if remainingPath == "random" {
|
||||||
@ -139,11 +139,11 @@ func (this *WikiServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
chosenArticle := titles[rand.Intn(len(titles))]
|
chosenArticle := titles[rand.Intn(len(titles))]
|
||||||
this.serveRedirect(w, this.opts.ExpectBaseURL+`view/`+url.QueryEscape(chosenArticle))
|
this.serveRedirect(w, this.opts.ExpectBaseURL+`view/`+url.PathEscape(chosenArticle))
|
||||||
return
|
return
|
||||||
|
|
||||||
} else if strings.HasPrefix(remainingPath, "view/") {
|
} else if strings.HasPrefix(remainingPath, "view/") {
|
||||||
articleTitle, err := url.QueryUnescape(remainingPath[len("view/"):])
|
articleTitle, err := url.PathUnescape(remainingPath[len("view/"):])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.serveErrorMessage(w, err)
|
this.serveErrorMessage(w, err)
|
||||||
return
|
return
|
||||||
@ -152,7 +152,7 @@ func (this *WikiServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
|
|
||||||
} else if strings.HasPrefix(remainingPath, "modify/") {
|
} else if strings.HasPrefix(remainingPath, "modify/") {
|
||||||
articleTitle, err := url.QueryUnescape(remainingPath[len("modify/"):])
|
articleTitle, err := url.PathUnescape(remainingPath[len("modify/"):])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.serveErrorMessage(w, err)
|
this.serveErrorMessage(w, err)
|
||||||
return
|
return
|
||||||
@ -161,7 +161,7 @@ func (this *WikiServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
|
|
||||||
} else if strings.HasPrefix(remainingPath, "history/") {
|
} else if strings.HasPrefix(remainingPath, "history/") {
|
||||||
articleTitle, err := url.QueryUnescape(remainingPath[len("history/"):])
|
articleTitle, err := url.PathUnescape(remainingPath[len("history/"):])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.serveErrorMessage(w, err)
|
this.serveErrorMessage(w, err)
|
||||||
return
|
return
|
||||||
@ -261,7 +261,7 @@ func (this *WikiServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
this.serveRedirect(w, this.opts.ExpectBaseURL+`view/`+url.QueryEscape(title))
|
this.serveRedirect(w, this.opts.ExpectBaseURL+`view/`+url.PathEscape(title))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,10 +45,10 @@ func (this *BBCodeRenderer) bbcode(data string) string {
|
|||||||
pregReplaceRule{regexp.MustCompile(`(?si)\[\*\]`), `</li><li>`, nil},
|
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)\[url=(.*?)\](.*?)\[/url\]`), `<a rel="noreferrer" href="$1">$2</a>`, nil},
|
||||||
pregReplaceRule{regexp.MustCompile(`(?si)\[article=(.*?)\](.*?)\[/article\]`), "", func(m []string) string {
|
pregReplaceRule{regexp.MustCompile(`(?si)\[article=(.*?)\](.*?)\[/article\]`), "", func(m []string) string {
|
||||||
return `<a href="` + template.HTMLEscapeString(this.baseUrl+`view/`+url.QueryEscape(m[1])) + `">` + m[2] + `</a>`
|
return `<a href="` + template.HTMLEscapeString(this.baseUrl+`view/`+url.PathEscape(m[1])) + `">` + m[2] + `</a>`
|
||||||
}},
|
}},
|
||||||
pregReplaceRule{regexp.MustCompile(`(?si)\[rev=(.*?)\](.*?)\[/rev\]`), "", func(m []string) string {
|
pregReplaceRule{regexp.MustCompile(`(?si)\[rev=(.*?)\](.*?)\[/rev\]`), "", func(m []string) string {
|
||||||
return `<a href="` + template.HTMLEscapeString(this.baseUrl+`archive/`+url.QueryEscape(m[1])) + `">` + m[2] + `</a>`
|
return `<a href="` + template.HTMLEscapeString(this.baseUrl+`archive/`+url.PathEscape(m[1])) + `">` + m[2] + `</a>`
|
||||||
}},
|
}},
|
||||||
|
|
||||||
pregReplaceRule{regexp.MustCompile(`(?si)\[imgur\](.*?)\.(...)\[/imgur\]`),
|
pregReplaceRule{regexp.MustCompile(`(?si)\[imgur\](.*?)\.(...)\[/imgur\]`),
|
||||||
|
@ -30,7 +30,7 @@ func (this *WikiServer) routeArchive(w http.ResponseWriter, r *http.Request, rev
|
|||||||
`<div class="info">`+
|
`<div class="info">`+
|
||||||
`You are viewing specific revision of this page, last modified `+
|
`You are viewing specific revision of this page, last modified `+
|
||||||
time.Unix(a.Modified, 0).In(this.loc).Format(this.opts.DateFormat)+`. `+
|
time.Unix(a.Modified, 0).In(this.loc).Format(this.opts.DateFormat)+`. `+
|
||||||
`Click <a href="`+template.HTMLEscapeString(this.opts.ExpectBaseURL+`view/`+url.QueryEscape(a.Title))+`">here</a> to see the latest revision.`+
|
`Click <a href="`+template.HTMLEscapeString(this.opts.ExpectBaseURL+`view/`+url.PathEscape(a.Title))+`">here</a> to see the latest revision.`+
|
||||||
`</div>`,
|
`</div>`,
|
||||||
) + bcr.RenderHTML(string(a.Body))
|
) + bcr.RenderHTML(string(a.Body))
|
||||||
pto.LoadCodeResources = bcr.CodePresent
|
pto.LoadCodeResources = bcr.CodePresent
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (this *WikiServer) noSuchArticleError(title string) template.HTML {
|
func (this *WikiServer) noSuchArticleError(title string) template.HTML {
|
||||||
return template.HTML(`No such article exists. <a href="` + this.opts.ExpectBaseURL + `modify/` + template.HTMLEscapeString(url.QueryEscape(title)) + `">Click here</a> to create it.`)
|
return template.HTML(`No such article exists. <a href="` + this.opts.ExpectBaseURL + `modify/` + template.HTMLEscapeString(url.PathEscape(title)) + `">Click here</a> to create it.`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *WikiServer) serveErrorMessage(w http.ResponseWriter, message error) {
|
func (this *WikiServer) serveErrorMessage(w http.ResponseWriter, message error) {
|
||||||
@ -22,7 +22,7 @@ func (this *WikiServer) serveInternalError(w http.ResponseWriter, r *http.Reques
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *WikiServer) serveErrorHTMLMessage(w http.ResponseWriter, msg template.HTML) {
|
func (this *WikiServer) serveErrorHTMLMessage(w http.ResponseWriter, msg template.HTML) {
|
||||||
this.serveRedirect(w, this.opts.ExpectBaseURL+"view/"+url.QueryEscape(this.opts.DefaultPage)+"?error="+url.QueryEscape(string(msg)))
|
this.serveRedirect(w, this.opts.ExpectBaseURL+"view/"+url.PathEscape(this.opts.DefaultPage)+"?error="+url.QueryEscape(string(msg)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *WikiServer) serveRedirect(w http.ResponseWriter, location string) {
|
func (this *WikiServer) serveRedirect(w http.ResponseWriter, location string) {
|
||||||
@ -46,5 +46,5 @@ func (this *WikiServer) formatTimestamp(m int64) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *WikiServer) viewLink(articleTitle string) template.HTML {
|
func (this *WikiServer) viewLink(articleTitle string) template.HTML {
|
||||||
return template.HTML(`"<a href="` + template.HTMLEscapeString(this.opts.ExpectBaseURL+`view/`+url.QueryEscape(articleTitle)) + `">` + template.HTMLEscapeString(articleTitle) + `</a>"`)
|
return template.HTML(`"<a href="` + template.HTMLEscapeString(this.opts.ExpectBaseURL+`view/`+url.PathEscape(articleTitle)) + `">` + template.HTMLEscapeString(articleTitle) + `</a>"`)
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ func (this *WikiServer) routeHistory(w http.ResponseWriter, r *http.Request, art
|
|||||||
pto.CurrentPageIsArticle = true
|
pto.CurrentPageIsArticle = true
|
||||||
|
|
||||||
content := `<h2>Page History</h2><br>` +
|
content := `<h2>Page History</h2><br>` +
|
||||||
`<em>There have been ` + fmt.Sprintf("%d", len(revs)) + ` edits to the page "<a href="` + template.HTMLEscapeString(this.opts.ExpectBaseURL+`view/`+url.QueryEscape(articleTitle)) + `">` + template.HTMLEscapeString(articleTitle) + `</a>".</em>` +
|
`<em>There have been ` + fmt.Sprintf("%d", len(revs)) + ` edits to the page "<a href="` + template.HTMLEscapeString(this.opts.ExpectBaseURL+`view/`+url.PathEscape(articleTitle)) + `">` + template.HTMLEscapeString(articleTitle) + `</a>".</em>` +
|
||||||
`<br><br>` +
|
`<br><br>` +
|
||||||
`<form method="GET" action="` + template.HTMLEscapeString(this.opts.ExpectBaseURL+`diff`) + `">` +
|
`<form method="GET" action="` + template.HTMLEscapeString(this.opts.ExpectBaseURL+`diff`) + `">` +
|
||||||
`<table>`
|
`<table>`
|
||||||
|
@ -22,7 +22,7 @@ func (this *WikiServer) routeIndex(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
content := fmt.Sprintf(`<h2>Article Index</h2><br><em>There are %d edits to %d pages.</em><br><br><ul>`, totalRevs, len(titles))
|
content := fmt.Sprintf(`<h2>Article Index</h2><br><em>There are %d edits to %d pages.</em><br><br><ul>`, totalRevs, len(titles))
|
||||||
for _, title := range titles {
|
for _, title := range titles {
|
||||||
content += `<li><a href="` + template.HTMLEscapeString(this.opts.ExpectBaseURL+`view/`+url.QueryEscape(title)) + `">` + template.HTMLEscapeString(title) + `</a></li>`
|
content += `<li><a href="` + template.HTMLEscapeString(this.opts.ExpectBaseURL+`view/`+url.PathEscape(title)) + `">` + template.HTMLEscapeString(title) + `</a></li>`
|
||||||
}
|
}
|
||||||
content += `</ul>`
|
content += `</ul>`
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ func (this *WikiServer) routeModify(w http.ResponseWriter, r *http.Request, arti
|
|||||||
pageTitleHTML = `Creating new article`
|
pageTitleHTML = `Creating new article`
|
||||||
baseRev = 0
|
baseRev = 0
|
||||||
} else {
|
} else {
|
||||||
pageTitleHTML = `Editing article "<a href="` + template.HTMLEscapeString(this.opts.ExpectBaseURL+`view/`+url.QueryEscape(articleTitle)) + `">` + template.HTMLEscapeString(articleTitle) + `</a>"`
|
pageTitleHTML = `Editing article "<a href="` + template.HTMLEscapeString(this.opts.ExpectBaseURL+`view/`+url.PathEscape(articleTitle)) + `">` + template.HTMLEscapeString(articleTitle) + `</a>"`
|
||||||
baseRev = a.ID
|
baseRev = a.ID
|
||||||
existingBody = string(a.Body)
|
existingBody = string(a.Body)
|
||||||
}
|
}
|
||||||
|
2
rRSS.go
2
rRSS.go
@ -33,7 +33,7 @@ func (this *WikiServer) routeRecentChangesRSS(w http.ResponseWriter, r *http.Req
|
|||||||
<author>` + template.HTMLEscapeString(this.opts.DeclareRSSEmail+` (`+this.opts.PageTitle+` `+a.Author+`)`) + `</author>
|
<author>` + template.HTMLEscapeString(this.opts.DeclareRSSEmail+` (`+this.opts.PageTitle+` `+a.Author+`)`) + `</author>
|
||||||
<pubDate>` + template.HTMLEscapeString(time.Unix(a.Modified, 0).In(this.loc).Format(time.RFC1123Z)) + `</pubDate>
|
<pubDate>` + template.HTMLEscapeString(time.Unix(a.Modified, 0).In(this.loc).Format(time.RFC1123Z)) + `</pubDate>
|
||||||
<description>` + template.HTMLEscapeString(`
|
<description>` + template.HTMLEscapeString(`
|
||||||
<a href="`+template.HTMLEscapeString(this.opts.ExternalBaseURL+`view/`+url.QueryEscape(a.Title))+`">latest version</a>
|
<a href="`+template.HTMLEscapeString(this.opts.ExternalBaseURL+`view/`+url.PathEscape(a.Title))+`">latest version</a>
|
||||||
|
|
|
|
||||||
<a href="`+template.HTMLEscapeString(this.opts.ExternalBaseURL+`archive/`+fmt.Sprintf("%d", a.ID))+`">revision `+fmt.Sprintf("%d", a.ID)+`</a>
|
<a href="`+template.HTMLEscapeString(this.opts.ExternalBaseURL+`archive/`+fmt.Sprintf("%d", a.ID))+`">revision `+fmt.Sprintf("%d", a.ID)+`</a>
|
||||||
|
|
|
|
||||||
|
@ -41,7 +41,7 @@ func (this *WikiServer) routeRecentChanges(w http.ResponseWriter, r *http.Reques
|
|||||||
`<table>`
|
`<table>`
|
||||||
for _, rev := range recents {
|
for _, rev := range recents {
|
||||||
content += `<tr>` +
|
content += `<tr>` +
|
||||||
`<td><a href="` + template.HTMLEscapeString(this.opts.ExpectBaseURL+`view/`+url.QueryEscape(rev.Title)) + `">` + template.HTMLEscapeString(rev.Title) + `</a>` +
|
`<td><a href="` + template.HTMLEscapeString(this.opts.ExpectBaseURL+`view/`+url.PathEscape(rev.Title)) + `">` + template.HTMLEscapeString(rev.Title) + `</a>` +
|
||||||
` [<a href="` + template.HTMLEscapeString(this.opts.ExpectBaseURL+`archive/`+fmt.Sprintf("%d", rev.ID)) + `">a</a>]` +
|
` [<a href="` + template.HTMLEscapeString(this.opts.ExpectBaseURL+`archive/`+fmt.Sprintf("%d", rev.ID)) + `">a</a>]` +
|
||||||
`</td>` +
|
`</td>` +
|
||||||
`<td>` + this.formatTimestamp(rev.Modified) + ` by ` + template.HTMLEscapeString(rev.Author) + `</td>` +
|
`<td>` + this.formatTimestamp(rev.Modified) + ` by ` + template.HTMLEscapeString(rev.Author) + `</td>` +
|
||||||
|
4
rView.go
4
rView.go
@ -2,11 +2,13 @@ package yatwiki
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (this *WikiServer) routeView(w http.ResponseWriter, r *http.Request, articleTitle string) {
|
func (this *WikiServer) routeView(w http.ResponseWriter, r *http.Request, articleTitle string) {
|
||||||
|
fmt.Printf("%#v\n", articleTitle)
|
||||||
a, err := this.db.GetLatestVersion(articleTitle)
|
a, err := this.db.GetLatestVersion(articleTitle)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
@ -15,7 +17,7 @@ func (this *WikiServer) routeView(w http.ResponseWriter, r *http.Request, articl
|
|||||||
// If this was an old link, it might not be present.
|
// If this was an old link, it might not be present.
|
||||||
// Redirect if possible
|
// Redirect if possible
|
||||||
if len(articleTitle) > 0 && articleTitle[len(articleTitle)-1] == '/' {
|
if len(articleTitle) > 0 && articleTitle[len(articleTitle)-1] == '/' {
|
||||||
this.serveRedirect(w, this.opts.ExpectBaseURL+"view/"+url.QueryEscape(articleTitle[0:len(articleTitle)-1]))
|
this.serveRedirect(w, this.opts.ExpectBaseURL+"view/"+url.PathEscape(articleTitle[0:len(articleTitle)-1]))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user