From 67804d252b630bd24c8188307fd8ef76a152c7ef Mon Sep 17 00:00:00 2001 From: Edgar HIPP Date: Thu, 21 Jan 2016 23:42:20 +0100 Subject: [PATCH] Add ip adress regression --- extractor.go | 2 +- pe_test.go | 5 +++++ validators.go | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/extractor.go b/extractor.go index 0a10361..a17bf8a 100644 --- a/extractor.go +++ b/extractor.go @@ -41,7 +41,7 @@ func GetAllMatches(input string, format string) []string { continue } - if isEmail(candidatePath) || isDate(candidatePath) || isVersion(candidatePath) || isGitRange(candidatePath) || isGitInstruction(candidatePath) || startsWithInvalidString(candidatePath) || endsWithInvalidString(candidatePath) || containsInvalidString(candidatePath) || len(candidatePath) <= 2 || isSpace(candidatePath) { + if isIp(candidatePath) || isEmail(candidatePath) || isDate(candidatePath) || isVersion(candidatePath) || isGitRange(candidatePath) || isGitInstruction(candidatePath) || startsWithInvalidString(candidatePath) || endsWithInvalidString(candidatePath) || containsInvalidString(candidatePath) || len(candidatePath) <= 2 || isSpace(candidatePath) { continue } if isGitPath(candidatePath) { diff --git a/pe_test.go b/pe_test.go index bc07d27..d6dfaa6 100644 --- a/pe_test.go +++ b/pe_test.go @@ -33,6 +33,11 @@ func TestEverything(t *testing.T) { t.Errorf("Matches sentence", output) } + output = GetAllMatches("0.0.0.0:3000", "") + if len(output) != 0 { + t.Errorf("Match ipadress", output) + } + output = GetAllMatches("'/usr/bin", "") if output[0] != "/usr/bin" { t.Errorf("Doesn't match statement correctly", output) diff --git a/validators.go b/validators.go index 60a817c..df6daf5 100644 --- a/validators.go +++ b/validators.go @@ -51,6 +51,11 @@ func replaceGitPath(input string) string { return string(temp[1]) } +func isIp(input string) bool { + r := regexp.MustCompile("^[0-9]{1,3}\\.[0-9x]{1,3}\\.[0-9x]{1,3}\\.[0-9x]{1,3}$") + return r.Match([]byte(input)) +} + func isVersion(input string) bool { r := regexp.MustCompile("^v?[0-9x]{1,3}\\.[0-9x]{1,3}(\\.[0-9x]{1,3})?$") return r.Match([]byte(input)) -- 2.44.0