Remove regexp for comment detection
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"regexp"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -31,8 +30,8 @@ func readTargets(source io.Reader) (Targets, error) {
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
|
||||
if !skipLine(line) { // Not a comment or blank line
|
||||
lines = append(lines, line)
|
||||
if line = strings.TrimSpace(line); line != "" && line[0:2] != "//" { // A comment or blank line
|
||||
lines = append(lines, line)
|
||||
}
|
||||
}
|
||||
if err := scanner.Err(); err != nil {
|
||||
@@ -42,10 +41,6 @@ func readTargets(source io.Reader) (Targets, error) {
|
||||
return NewTargets(lines)
|
||||
}
|
||||
|
||||
func skipLine(line string) (bool) {
|
||||
return regexp.MustCompile(`^\s*((\/\/)|$)`).MatchString(line)
|
||||
}
|
||||
|
||||
// NewTargets instantiates Targets from a slice of strings
|
||||
func NewTargets(lines []string) (Targets, error) {
|
||||
targets := make([]*http.Request, 0)
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func TestReadTargets(t *testing.T) {
|
||||
lines := bytes.NewBufferString("GET http://lolcathost:9999/\n\n // HEAD http://lolcathost.com this is a comment \nHEAD http://lolcathost:9999/\n")
|
||||
lines := bytes.NewBufferString("GET http://lolcathost:9999/\n\n // HEAD http://lolcathost.com this is a comment \nHEAD http://lolcathost:9999/\n")
|
||||
targets, err := readTargets(lines)
|
||||
if err != nil {
|
||||
t.Fatalf("Couldn't parse valid source: %s", err)
|
||||
|
||||
Reference in New Issue
Block a user