internal/redirect: add minor fixes from golang.org/x/tools/godoc/redirect
Change-Id: I7436b87c2fd952ad71f25affaf74944b6ec51e6f Reviewed-on: https://go-review.googlesource.com/c/website/+/293425 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
This commit is contained in:
Родитель
5bbf007a6d
Коммит
d6a1a7b134
|
@ -156,7 +156,7 @@ func Handler(target string) http.Handler {
|
|||
})
|
||||
}
|
||||
|
||||
var validId = regexp.MustCompile(`^[A-Za-z0-9-]*/?$`)
|
||||
var validID = regexp.MustCompile(`^[A-Za-z0-9-]*/?$`)
|
||||
|
||||
func PrefixHandler(prefix, baseURL string) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -166,7 +166,7 @@ func PrefixHandler(prefix, baseURL string) http.Handler {
|
|||
return
|
||||
}
|
||||
id := r.URL.Path[len(prefix):]
|
||||
if !validId.MatchString(id) {
|
||||
if !validID.MatchString(id) {
|
||||
http.Error(w, "Not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ func clHandler(w http.ResponseWriter, r *http.Request) {
|
|||
id := r.URL.Path[len(prefix):]
|
||||
// support /cl/152700045/, which is used in commit 0edafefc36.
|
||||
id = strings.TrimSuffix(id, "/")
|
||||
if !validId.MatchString(id) {
|
||||
if !validID.MatchString(id) {
|
||||
http.Error(w, "Not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ func TestRedirects(t *testing.T) {
|
|||
"/cl/152047": {302, "https://go-review.googlesource.com/152047"},
|
||||
"/cl/152048": {302, "https://codereview.appspot.com/152048"},
|
||||
|
||||
// And verify we're using the the "bigEnoughAssumeRietveld" value:
|
||||
// And verify we're using the "bigEnoughAssumeRietveld" value:
|
||||
"/cl/299999": {302, "https://go-review.googlesource.com/299999"},
|
||||
"/cl/300000": {302, "https://codereview.appspot.com/300000"},
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче