From: Edgar HIPP Date: Sat, 16 Jan 2016 07:12:13 +0000 (+0100) Subject: Add check for invalid strings X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;ds=sidebyside;h=db951ff7450aecc90594865f297cd3bb666bc2bc;p=path-extractor.git Add check for invalid strings --- 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 {