extractor.go | 2 +- pe_test.go | 5 +++++ validators.go | 10 ++++++++++ diff --git a/extractor.go b/extractor.go index 7d13650c008f6cc2b3907d23249ed5d58b8ddaec..d42bf0e0032767a5203c4f5ae72383dd0385436f 100644 --- a/extractor.go +++ b/extractor.go @@ -17,7 +17,7 @@ s := string("") matches = pathExtractor(input) for _, match := range matches { s = string(match[1]) - if isEmail(s) || isDate(s) || isVersion(s) || isGitRange(s) || isGitInstruction(s) || containsInvalidString(s) || len(s) <= 2 { + if isEmail(s) || isDate(s) || isVersion(s) || isGitRange(s) || isGitInstruction(s) || endsWithInvalidString(s) || containsInvalidString(s) || len(s) <= 2 { continue } if isGitPath(s) { diff --git a/pe_test.go b/pe_test.go index 948f82087693538893e6147e40efee60979dccbb..20999277318755174e7fede997d55104cb16c09d 100644 --- a/pe_test.go +++ b/pe_test.go @@ -8,6 +8,11 @@ if output[0] != "alt/generateStore.php" { t.Errorf("Doesnt match files", output) } + output = GetAllMatches("I have a cat.") + if len(output) != 0 { + t.Errorf("Matches sentence", output) + } + output = GetAllMatches("hello .gitignore") if output[0] != ".gitignore" { t.Errorf("Doesnt match hidden files", output) diff --git a/validators.go b/validators.go index bef5f6551fb36c07987424ab8006169af4d58d01..2ed2a880065e7d97e9f5d6e64b3c724edeeb71f4 100644 --- a/validators.go +++ b/validators.go @@ -56,6 +56,16 @@ r := regexp.MustCompile("[0-9x]\\.[0-9x]{1,2}(\\.[0-9x]{1,3})?") return r.Match([]byte(input)) } +func endsWithInvalidString(input string) bool { + invalidEndings := []string{"."} + for _, s := range invalidEndings { + if strings.LastIndex(input, s) == len(input)-len(s) { + return true + } + } + return false +} + func containsInvalidString(input string) bool { invalidStrings := []string{"(", ")", "and/or", "origin/", "{", "}", "<", ">", "$", "*"} for _, s := range invalidStrings {