fix: use regexTarget for extend config (#1536)

* fix: use regexTarget for extend config

* fix: add keywords from base and extended rule into global keywords list

* docs: add an example to extend default rules

* chore: update project URL references
This commit is contained in:
Roger Meier authored and GitHub committed 2024-09-29 15:45:56 -05:00
1 parent a0f2f4671c
commit a971a324fa
6 files changed
+27 -10

No files matched your search

+4
View File
@@ -252,7 +252,11 @@ func (c *Config) extend(extensionConfig Config) {
baseRule.Allowlist.Commits = append(baseRule.Allowlist.Commits, currentRule.Allowlist.Commits...)
baseRule.Allowlist.Paths = append(baseRule.Allowlist.Paths, currentRule.Allowlist.Paths...)
baseRule.Allowlist.Regexes = append(baseRule.Allowlist.Regexes, currentRule.Allowlist.Regexes...)
baseRule.Allowlist.RegexTarget = currentRule.Allowlist.RegexTarget
baseRule.Allowlist.StopWords = append(baseRule.Allowlist.StopWords, currentRule.Allowlist.StopWords...)
// The keywords from the base rule and the extended rule must be merged into the global keywords list
c.Keywords = append(c.Keywords, baseRule.Keywords...)
c.Keywords = append(c.Keywords, currentRule.Keywords...)
delete(c.Rules, ruleID)
c.Rules[ruleID] = baseRule
+1
View File
@@ -145,6 +145,7 @@ func TestTranslate(t *testing.T) {
Regexes: []*regexp.Regexp{
regexp.MustCompile(`foo.+bar`),
},
RegexTarget: "line",
Paths: []*regexp.Regexp{
regexp.MustCompile(`ignore\.xaml`),
},
+1 -1
View File
@@ -1,7 +1,7 @@
# This file has been auto-generated. Do not edit manually.
# If you would like to contribute new rules, please use
# cmd/generate/config/main.go and follow the contributing guidelines
# at https://github.com/zricethezav/gitleaks/blob/master/CONTRIBUTING.md
# at https://github.com/gitleaks/gitleaks/blob/master/CONTRIBUTING.md
# This is the default gitleaks configuration file.
# Rules and allowlists are defined within this file.