extractor.go | 2 +- pe_test.go | 10 ++++++++++ validators.go | 10 ++++++++++ diff --git a/extractor.go b/extractor.go index 2f764aa56183f02ddf6868fce4f23b87468297c3..11161a31f2795feb2d0b8b3bb591e295586d1c97 100644 --- a/extractor.go +++ b/extractor.go @@ -41,7 +41,7 @@ if len(input) >= len(candidatePath+"(") && strings.Index(input, candidatePath+"(") != -1 { 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 c9726174fd46962e9859cbaf13deb1ce41ecf0f8..dde9cf85de6df6f8275ed7dca7f3b895521ec6a1 100644 --- a/pe_test.go +++ b/pe_test.go @@ -157,6 +157,16 @@ if len(output) != 1 { 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 fe2156d3330572b6c612a18add76cda06ffbe8b6..5f67fdbc47851f7a3812d02b63799cf9175a2368 100644 --- a/validators.go +++ b/validators.go @@ -56,6 +56,16 @@ r := regexp.MustCompile("^v?[0-9x]\\.[0-9x]{1,2}(\\.[0-9x]{1,3})?$") 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 {