From f6aec750e6b44611e1ce1faffd770cb2a4287a88 Mon Sep 17 00:00:00 2001 From: The_Spider Date: Mon, 7 Feb 2022 07:58:43 -0600 Subject: [PATCH] Adds test to skip empty lines --- cmd/bind/parsing-complex.go | 8 ++++++++ cmd/bind/parsing-simple.go | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/cmd/bind/parsing-complex.go b/cmd/bind/parsing-complex.go index 9e24a91..7e74b41 100644 --- a/cmd/bind/parsing-complex.go +++ b/cmd/bind/parsing-complex.go @@ -3,6 +3,7 @@ package main import ( "bufio" "bytes" + "log" "regexp" "strings" @@ -25,6 +26,11 @@ func parseComplex(data []byte) []string { continue } + // skip lines with no characters and/or whitespace only + if regexp.MustCompile(`^(\s+)?$`).MatchString(line) { + continue + } + // split line by whitespace lineItems := strings.Fields(line) @@ -32,6 +38,8 @@ func parseComplex(data []byte) []string { // the second item is the domain, check if its valid and add it if govalidator.IsDNSName(lineItems[1]) { domains = append(domains, lineItems[1]) + } else { + log.Printf("[TRACE] Domain is not valid: %s\n", lineItems[0]) } } } diff --git a/cmd/bind/parsing-simple.go b/cmd/bind/parsing-simple.go index 3527a49..2d20dbd 100644 --- a/cmd/bind/parsing-simple.go +++ b/cmd/bind/parsing-simple.go @@ -3,6 +3,7 @@ package main import ( "bufio" "bytes" + "log" "regexp" "strings" @@ -25,6 +26,11 @@ func parseSimple(data []byte) []string { continue } + // skip lines with no characters and/or whitespace only + if regexp.MustCompile(`^(\s+)?$`).MatchString(line) { + continue + } + // split line by whitespace lineItems := strings.Fields(line) @@ -32,6 +38,8 @@ func parseSimple(data []byte) []string { // the second item is the domain, check if its valid and add it if govalidator.IsDNSName(lineItems[0]) { domains = append(domains, lineItems[0]) + } else { + log.Printf("[TRACE] Domain is not valid: %s\n", lineItems[0]) } } }