From db951ff7450aecc90594865f297cd3bb666bc2bc Mon Sep 17 00:00:00 2001 From: Edgar HIPP Date: Sat, 16 Jan 2016 08:12:13 +0100 Subject: [PATCH] Add check for invalid strings --- extractor.go | 2 +- pe_test.go | 10 ++++++++++ validators.go | 10 ++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/extractor.go b/extractor.go index 2f764aa..11161a3 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) || endsWithInvalidString(candidatePath) || containsInvalidString(candidatePath) || len(candidatePath) <= 2 { + if isEmail(candidatePath) || isDate(candidatePath) || isVersion(candidatePath) || isGitRange(candidatePath) || isGitInstruction(candidatePath) || startsWithInvalidString(candidatePath) || endsWithInvalidString(candidatePath) || containsInvalidString(candidatePath) || len(candidatePath) <= 2 { continue } if isGitPath(candidatePath) { diff --git a/pe_test.go b/pe_test.go index c972617..dde9cf8 100644 --- a/pe_test.go +++ b/pe_test.go @@ -157,6 +157,16 @@ func TestEverything(t *testing.T) { t.Errorf("Doesnt match multiple extensions", output) } + output = GetAllMatches("[Error/foobar]", "") + if len(output) == 1 { + t.Errorf("Matches error", output) + } + + output = GetAllMatches("[Object.foo]", "") + if len(output) == 1 { + t.Errorf("Matches Object.foo", output) + } + output = GetAllMatches("(user.js)", "") if len(output) != 1 { t.Errorf("Doesnt match surrounded by parens", output) diff --git a/validators.go b/validators.go index fe2156d..5f67fdb 100644 --- a/validators.go +++ b/validators.go @@ -56,6 +56,16 @@ func isVersion(input string) bool { return r.Match([]byte(input)) } +func startsWithInvalidString(input string) bool { + invalidBeginnings := []string{"Error/", "Object.", "Array."} + for _, s := range invalidBeginnings { + if strings.Index(input, s) == 0 { + return true + } + } + return false +} + func endsWithInvalidString(input string) bool { invalidEndings := []string{"."} for _, s := range invalidEndings { -- 2.48.1