]> Sergey Matveev's repositories - path-extractor.git/commitdiff
Check if path ends with '.', if yes, invalid path
authorEdgar HIPP <hipp.edg@gmail.com>
Sun, 30 Aug 2015 15:06:56 +0000 (17:06 +0200)
committerEdgar HIPP <hipp.edg@gmail.com>
Sun, 30 Aug 2015 15:06:56 +0000 (17:06 +0200)
extractor.go
pe_test.go
validators.go

index 7d13650c008f6cc2b3907d23249ed5d58b8ddaec..d42bf0e0032767a5203c4f5ae72383dd0385436f 100644 (file)
@@ -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) {
index 948f82087693538893e6147e40efee60979dccbb..20999277318755174e7fede997d55104cb16c09d 100644 (file)
@@ -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)
index bef5f6551fb36c07987424ab8006169af4d58d01..2ed2a880065e7d97e9f5d6e64b3c724edeeb71f4 100644 (file)
@@ -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 {