Skip to content

Commit

Permalink
[fix] reduce cyclomatic complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
asciimoo committed May 13, 2018
1 parent 6a6c784 commit 488e630
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions colly.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,26 +610,12 @@ func (c *Collector) requestCheck(u, method string, depth int, checkRevisit bool)
return ErrMaxDepth
}
if len(c.DisallowedURLFilters) > 0 {
matched := false
for _, r := range c.DisallowedURLFilters {
if r.Match([]byte(u)) {
matched = true
break
}
}
if matched {
if isMatchingFilter(c.DisallowedURLFilters, []byte(u)) {
return ErrForbiddenURL
}
}
if len(c.URLFilters) > 0 {
matched := false
for _, r := range c.URLFilters {
if r.Match([]byte(u)) {
matched = true
break
}
}
if !matched {
if !isMatchingFilter(c.URLFilters, []byte(u)) {
return ErrNoURLFiltersMatch
}
}
Expand Down Expand Up @@ -1261,3 +1247,12 @@ func (j *cookieJarSerializer) Cookies(u *url.URL) []*http.Cookie {
}
return cnew
}

func isMatchingFilter(fs []*regexp.Regexp, d []byte) bool {
for _, r := range fs {
if r.Match(d) {
return true
}
}
return false
}

0 comments on commit 488e630

Please sign in to comment.