mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-29 12:44:22 +01:00
Add support for reportGroup (#456)
Why: * There are times where it would be nice to have a group from the regex reported rather than the complete match. This change addresses the need by: * Add the reportGroup configuration option for a rule. * Update scan.CheckRules to return the reportGroup if set. Co-authored-by: Daniel Paul Searles <dsearles@gitlab.com>
This commit is contained in:
1 parent
ede68fd95d
commit
2acc34dfdf
6 files changed
+158
No files matched your search
@@ -121,6 +121,11 @@ func (repo *Repo) CheckRules(bundle *Bundle) {
|
||||
continue
|
||||
}
|
||||
|
||||
// 0 is a match for the full regex pattern
|
||||
if 0 < rule.ReportGroup && rule.ReportGroup < len(groups) {
|
||||
offender = groups[rule.ReportGroup]
|
||||
}
|
||||
|
||||
leak := manager.Leak{
|
||||
LineNumber: defaultLineNumber,
|
||||
Line: line,
|
||||
|
||||
@@ -144,6 +144,17 @@ func TestScan(t *testing.T) {
|
||||
},
|
||||
wantEmpty: true,
|
||||
},
|
||||
{
|
||||
description: "test local repo three leaks dev branch with reportGroup set",
|
||||
opts: options.Options{
|
||||
RepoPath: "../test_data/test_repos/test_repo_3",
|
||||
Report: "../test_data/test_local_repo_three_leaks_with_report_groups.json.got",
|
||||
Config: "../test_data/test_configs/aws_key_with_report_groups.toml",
|
||||
Branch: "dev",
|
||||
ReportFormat: "json",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_three_leaks_with_report_groups.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo three leaks dev branch",
|
||||
opts: options.Options{
|
||||
|
||||
Reference in new issue
Block a user