Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent re-compilation of known regex patterns when ignoring allowed patterns #245

Merged
merged 2 commits into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ detector/.talismanrc
coverage.out
coverage.txt
.talismanrc
talisman_reports/
13 changes: 11 additions & 2 deletions detector/pattern/pattern_detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,18 @@ func (detector PatternDetector) Test(comparator helpers.ChecksumCompare, current
}
}

var knownPatterns = make(map[string]*regexp.Regexp)

func replaceAllStrings(str string, pattern string) string {
re := regexp.MustCompile(fmt.Sprintf("(?i)%s", pattern))
return re.ReplaceAllString(str, "")
var pat *regexp.Regexp
var ok bool

if pat, ok = knownPatterns[pattern]; !ok {
pat = regexp.MustCompile(fmt.Sprintf("(?i)%s", pattern))
knownPatterns[pattern] = pat
}

return pat.ReplaceAllString(str, "")
}

func processAllowedPatterns(addition gitrepo.Addition, tRC *talismanrc.TalismanRC) string {
Expand Down
253 changes: 0 additions & 253 deletions talisman_reports/report.html

This file was deleted.

1 change: 0 additions & 1 deletion talisman_reports/report.json

This file was deleted.