4
0
Эх сурвалжийг харах

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 <zricezrice@gmail.com>
Co-authored-by: Richard Gomez <32133502+rgmz@users.noreply.github.com>
h4r7w3l1 1 жил өмнө
parent
commit
97dbe1ef09

+ 5 - 1
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
 }

+ 1 - 0
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