Skip to content

Commit

Permalink
chore: refactor regex for redundant pipe (#2)
Browse files Browse the repository at this point in the history
### Description:
> since this part is enclosed in `[]`, the pipes aren't necessary.

_Originally posted by @rgmz in
gitleaks#1265 (comment)

### Checklist:

* [x] Does your PR pass tests?
* [x] Have you written new tests for your changes?
* [x] Have you lint your code locally prior to submission?

Original: gitleaks#1266
  • Loading branch information
baruchiro committed Mar 28, 2024
1 parent 93df1a4 commit 170b7c8
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 126 deletions.
6 changes: 3 additions & 3 deletions cmd/generate/config/rules/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ const (
identifierCaseInsensitivePrefix = `(?i:`
identifierCaseInsensitiveSuffix = `)`
identifierPrefix = `(?:`
identifierSuffix = `)(?:[0-9a-z\-_\t .]{0,20})(?:[\s|']|[\s|"]){0,3}`
identifierSuffix = `)(?:[0-9a-z\-_\t .]{0,20})(?:[\s'"]){0,3}`

// commonly used assignment operators or function call
operator = `(?:=|>|:{1,3}=|\|\|:|<=|=>|:|\?=)`

// boundaries for the secret
// \x60 = `
secretPrefixUnique = `\b(`
secretPrefix = `(?:'|\"|\s|=|\x60){0,5}(`
secretSuffix = `)(?:['|\"|\n|\r|\s|\x60|;|<]|$)`
secretPrefix = `(?:['\"\s=\x60]){0,5}(`
secretSuffix = `)(?:['\"\n\r\s\x60;<]|$)`
)

func generateSemiGenericRegex(identifiers []string, secretRegex string, isCaseInsensitive bool) *regexp.Regexp {
Expand Down
Loading

0 comments on commit 170b7c8

Please sign in to comment.