From 97dbe1ef0969f6162e061a5418063f19ed729497 Mon Sep 17 00:00:00 2001 From: h4r7w3l1 <36492399+h4r7w3l1@users.noreply.github.com> Date: Wed, 18 Sep 2024 21:44:44 +0300 Subject: [PATCH] Add support in .gitleaksignore file comment strings (#1425) (#1502) * Add support in .gitleaksignore file comment strings (#1195) * Apply suggestions from code review Co-authored-by: Richard Gomez <32133502+rgmz@users.noreply.github.com> --------- Co-authored-by: Zachary Rice Co-authored-by: Richard Gomez <32133502+rgmz@users.noreply.github.com> --- detect/detect.go | 6 +++++- testdata/repos/small/.gitleaksignore | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/detect/detect.go b/detect/detect.go index 95714771..15cc870d 100644 --- a/detect/detect.go +++ b/detect/detect.go @@ -149,7 +149,11 @@ func (d *Detector) AddGitleaksIgnore(gitleaksIgnorePath string) error { scanner := bufio.NewScanner(file) for scanner.Scan() { - d.gitleaksIgnore[scanner.Text()] = true + line := strings.TrimSpace(scanner.Text()) + // Skip lines that start with a comment + if line != "" && !strings.HasPrefix(line, "#") { + d.gitleaksIgnore[line] = true + } } return nil } diff --git a/testdata/repos/small/.gitleaksignore b/testdata/repos/small/.gitleaksignore index 8a845a7e..880403db 100644 --- a/testdata/repos/small/.gitleaksignore +++ b/testdata/repos/small/.gitleaksignore @@ -1,2 +1,3 @@ api/ignoreGlobal.go:aws-access-key:20 +# test comment 53cd7a3c6eb4937f413e3c25e4a9f39289afa69e:api/ignoreCommit.go:aws-access-key:20