]> Sergey Matveev's repositories - path-extractor.git/commitdiff
Add check for invalid strings
authorEdgar HIPP <hipp.edg@gmail.com>
Sat, 16 Jan 2016 07:12:13 +0000 (08:12 +0100)
committerEdgar HIPP <hipp.edg@gmail.com>
Sat, 16 Jan 2016 07:12:13 +0000 (08:12 +0100)
extractor.go
pe_test.go
validators.go

index 2f764aa56183f02ddf6868fce4f23b87468297c3..11161a31f2795feb2d0b8b3bb591e295586d1c97 100644 (file)
@@ -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) {
index c9726174fd46962e9859cbaf13deb1ce41ecf0f8..dde9cf85de6df6f8275ed7dca7f3b895521ec6a1 100644 (file)
@@ -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)
index fe2156d3330572b6c612a18add76cda06ffbe8b6..5f67fdbc47851f7a3812d02b63799cf9175a2368 100644 (file)
@@ -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 {