Skip to content

Commit 4d81e11

Browse files
minuxadg
authored andcommitted
godoc/redirect: update the rules for /cl/ redirect
If id is a number greater than 150k, then it is a Rietveld CL, otherwise treat it as a Gerrit change id. Also add support for /cl/ID/, because go commit 0edafefc36 uses this form. Change-Id: I46575e3284faaa727e346b34bbc46ab248cf12b3 Signed-off-by: Shenghou Ma <[email protected]> Reviewed-on: https://go-review.googlesource.com/1283 Reviewed-by: Andrew Gerrand <[email protected]>
1 parent 71d0144 commit 4d81e11

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

godoc/redirect/redirect.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,19 @@ func clHandler(w http.ResponseWriter, r *http.Request) {
177177
return
178178
}
179179
id := r.URL.Path[len(prefix):]
180+
// support /cl/152700045/, which is used in commit 0edafefc36.
181+
id = strings.TrimSuffix(id, "/")
180182
if !validId.MatchString(id) {
181183
http.Error(w, "Not found", http.StatusNotFound)
182184
return
183185
}
184186
target := ""
185-
// the first CL in rietveld is about 152046, so if id is less than
186-
// 150000, treat it as a Gerrit change id.
187-
if n, _ := strconv.Atoi(id); strings.HasPrefix(id, "I") || n < 150000 {
188-
target = "https://go-review.googlesource.com/#/q/" + id
189-
} else {
187+
// the first CL in rietveld is about 152046, so only treat the id as
188+
// a rietveld CL if it is larger than 150000.
189+
if n, err := strconv.Atoi(id); err == nil && n > 150000 {
190190
target = "https://codereview.appspot.com/" + id
191+
} else {
192+
target = "https://go-review.googlesource.com/r/" + id
191193
}
192194
http.Redirect(w, r, target, http.StatusFound)
193195
}

0 commit comments

Comments
 (0)