include default newline pairs when calculating location (#1038)

* include default newline pairs when calculating location
This commit is contained in:
Zachary Rice authored and GitHub committed 2022-11-20 12:34:38 -06:00
1 parent d0733f96f3
commit 7f229faf12
2 files changed
+31 -16

No files matched your search

+10
View File
@@ -24,6 +24,16 @@ func location(fragment Fragment, matchIndex []int) Location {
// default startLineIndex to 0
location.startLineIndex = 0
// Fixes: https://github.com/zricethezav/gitleaks/issues/1037
// When a fragment does NOT have any newlines, a default "newline"
// will be counted to make the subsequent location calculation logic work
// for fragments will no newlines.
if len(fragment.newlineIndices) == 0 {
fragment.newlineIndices = [][]int{
{len(fragment.Raw), len(fragment.Raw) + 1},
}
}
for lineNum, pair := range fragment.newlineIndices {
_lineNum = lineNum
newLineByteIndex := pair[0]