From 31eff7bf8d9b4955e5099e0cd3424bd587ad9e50 Mon Sep 17 00:00:00 2001 From: Edgar HIPP Date: Sun, 30 Aug 2015 17:06:56 +0200 Subject: [PATCH] Check if path ends with '.', if yes, invalid path --- extractor.go | 2 +- pe_test.go | 5 +++++ validators.go | 10 ++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/extractor.go b/extractor.go index 7d13650..d42bf0e 100644 --- a/extractor.go +++ b/extractor.go @@ -17,7 +17,7 @@ func GetAllMatches(input string) []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 948f820..2099927 100644 --- a/pe_test.go +++ b/pe_test.go @@ -8,6 +8,11 @@ func TestGitIgnore(t *testing.T) { 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 bef5f65..2ed2a88 100644 --- a/validators.go +++ b/validators.go @@ -56,6 +56,16 @@ func isVersion(input string) bool { 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 { -- 2.44.0