Correct benign mistake in off-by-one guard

m[2] is the third element of m, rather than the second, so we have to
check instead that the len of m is at least 3.

Because the regular expression has two capture groups, the length of m
will always be 3, so currently the guard will always be true.
This commit is contained in:
Robin Neatherway 2021-08-19 14:41:04 +01:00
parent 8a56359902
commit 0e51ec1699
2 changed files with 2 additions and 2 deletions

View file

@ -14,7 +14,7 @@ var linkRE = regexp.MustCompile(`<([^>]+)>;\s*rel="([^"]+)"`)
func findNextPage(resp *http.Response) (string, bool) {
for _, m := range linkRE.FindAllStringSubmatch(resp.Header.Get("Link"), -1) {
if len(m) >= 2 && m[2] == "next" {
if len(m) > 2 && m[2] == "next" {
return m[1], true
}
}

View file

@ -250,7 +250,7 @@ var linkRE = regexp.MustCompile(`<([^>]+)>;\s*rel="([^"]+)"`)
func findNextPage(link string) string {
for _, m := range linkRE.FindAllStringSubmatch(link, -1) {
if len(m) >= 2 && m[2] == "next" {
if len(m) > 2 && m[2] == "next" {
return m[1]
}
}