Browse Source

Fixed allowed domains being broken when an empty string was specified in the configuration file

master
parent
commit
36b887f372
  1. 21
      src/main.go
  2. 2
      src/worker/worker.go

21
src/main.go

@ -28,6 +28,7 @@ import (
"os" "os"
"os/signal" "os/signal"
"path/filepath" "path/filepath"
"strings"
"time" "time"
"unbewohnte/wecr/config" "unbewohnte/wecr/config"
"unbewohnte/wecr/logger" "unbewohnte/wecr/logger"
@ -175,7 +176,12 @@ func main() {
return return
} }
for index, blacklistedDomain := range conf.BlacklistedDomains { var sanitizedBlacklistedDomains []string
for _, blacklistedDomain := range conf.BlacklistedDomains {
if strings.TrimSpace(blacklistedDomain) == "" {
continue
}
parsedURL, err := url.Parse(blacklistedDomain) parsedURL, err := url.Parse(blacklistedDomain)
if err != nil { if err != nil {
logger.Warning("Failed to parse blacklisted \"%s\": %s", blacklistedDomain, err) logger.Warning("Failed to parse blacklisted \"%s\": %s", blacklistedDomain, err)
@ -188,10 +194,16 @@ func main() {
continue continue
} }
conf.BlacklistedDomains[index] = parsedURL.Host sanitizedBlacklistedDomains = append(sanitizedBlacklistedDomains, parsedURL.Host)
}
conf.BlacklistedDomains = sanitizedBlacklistedDomains
var sanitizedAllowedDomains []string
for _, allowedDomain := range conf.AllowedDomains {
if strings.TrimSpace(allowedDomain) == "" {
continue
} }
for index, allowedDomain := range conf.AllowedDomains {
parsedURL, err := url.Parse(allowedDomain) parsedURL, err := url.Parse(allowedDomain)
if err != nil { if err != nil {
logger.Warning("Failed to parse allowed \"%s\": %s", allowedDomain, err) logger.Warning("Failed to parse allowed \"%s\": %s", allowedDomain, err)
@ -204,8 +216,9 @@ func main() {
continue continue
} }
conf.AllowedDomains[index] = parsedURL.Host sanitizedAllowedDomains = append(sanitizedAllowedDomains, parsedURL.Host)
} }
conf.AllowedDomains = sanitizedAllowedDomains
if conf.Depth <= 0 { if conf.Depth <= 0 {
conf.Depth = 1 conf.Depth = 1

2
src/worker/worker.go

@ -93,13 +93,13 @@ func (w *Worker) Work() {
return return
} }
var skip bool = false
pageURL, err := url.Parse(job.URL) pageURL, err := url.Parse(job.URL)
if err != nil { if err != nil {
logger.Error("Failed to parse URL \"%s\" to get hostname: %s", job.URL, err) logger.Error("Failed to parse URL \"%s\" to get hostname: %s", job.URL, err)
continue continue
} }
var skip bool = false
// see if the domain is allowed and is not blacklisted // see if the domain is allowed and is not blacklisted
if len(w.Conf.AllowedDomains) > 0 { if len(w.Conf.AllowedDomains) > 0 {
skip = true skip = true

Loading…
Cancel
Save