Compare commits

...
1 Commits
Author SHA1 Message Date
Zachary Rice 6c60c3dde3 Adding some logic to fix line number extractor when there are multipl… (#436)
* Adding some logic to fix line number extractor when there are multiple secrets of the same offender within the same patch

* formatting some consts
2020-09-01 20:48:43 -04:00
+16 -5
View File
@@ -20,11 +20,12 @@ import (
)
const (
diffAddPrefix = "+"
diffAddFilePrefix = "+++ b"
diffAddFilePrefixSlash = "+++ b/"
diffLineSignature = " @@"
defaultLineNumber = -1
diffAddPrefix = "+"
diffAddFilePrefix = "+++ b"
diffAddFilePrefixSlash = "+++ b/"
diffLineSignature = " @@"
diffLineSignaturePrefix = "@@ "
defaultLineNumber = -1
)
// CheckRules accepts bundle and checks each rule defined in the config against the bundle's content.
@@ -238,6 +239,16 @@ func extractAndInjectLineNumber(leak *manager.Leak, bundle *Bundle, repo *Repo)
leak.LineNumber = potentialLine
return
}
} else if strings.HasPrefix(txt, diffLineSignaturePrefix) && currStartDiffLine != 0 {
// This logic is used for when there are multiple leaks of the same offender within the same patch
i := strings.Index(txt, diffAddPrefix)
pairs := strings.Split(strings.Split(txt[i+1:], diffLineSignature)[0], ",")
currStartDiffLine, err = strconv.Atoi(pairs[0])
if err != nil {
log.Debug(err)
return
}
currLine = 0
}
currLine++
}