Skip to content

Commit ded5f45

Browse files
authored
[fix] - Sonarcloud detector (#3982)
1 parent ef3a714 commit ded5f45

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

pkg/detectors/sonarcloud/sonarcloud.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var (
2121
client = common.SaneHttpClient()
2222

2323
// Make sure that your group is surrounded in boundary characters such as below to reduce false positives.
24-
keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"sonar"}) + `\b([0-9a-z]{40})\b`)
24+
keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"sonar"}) + `(?:^|[^@])\b([0-9a-z]{40})\b`)
2525
)
2626

2727
// Keywords are used for efficiently pre-filtering chunks.

pkg/detectors/sonarcloud/sonarcloud_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ func TestSonarCloud_Pattern(t *testing.T) {
4545
input: fmt.Sprintf("%s = '%s'", keyword, invalidPattern),
4646
want: []string{},
4747
},
48+
{
49+
name: "invalid pattern - token directly preceded by @",
50+
input: fmt.Sprintf("%s token = '@%s'", keyword, validPattern),
51+
want: []string{},
52+
},
4853
}
4954

5055
for _, test := range tests {

0 commit comments

Comments
 (0)