mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-30 21:24:21 +01:00
fixing a location off by one edge case for --no-git (#812)
This commit is contained in:
1 parent
31ff8677dd
commit
ba9e089e35
2 files changed
+10
-11
No files matched your search
@@ -84,8 +84,8 @@ func TestDetect(t *testing.T) {
|
|||||||
File: "tmp.go",
|
File: "tmp.go",
|
||||||
RuleID: "pypi-upload-token",
|
RuleID: "pypi-upload-token",
|
||||||
Tags: []string{"key", "pypi"},
|
Tags: []string{"key", "pypi"},
|
||||||
StartLine: 0,
|
StartLine: 1,
|
||||||
EndLine: 0,
|
EndLine: 1,
|
||||||
StartColumn: 1,
|
StartColumn: 1,
|
||||||
EndColumn: 86,
|
EndColumn: 86,
|
||||||
Entropy: 1.9606875,
|
Entropy: 1.9606875,
|
||||||
@@ -106,8 +106,8 @@ func TestDetect(t *testing.T) {
|
|||||||
File: "tmp.go",
|
File: "tmp.go",
|
||||||
RuleID: "aws-access-key",
|
RuleID: "aws-access-key",
|
||||||
Tags: []string{"key", "AWS"},
|
Tags: []string{"key", "AWS"},
|
||||||
StartLine: 0,
|
StartLine: 1,
|
||||||
EndLine: 0,
|
EndLine: 1,
|
||||||
StartColumn: 15,
|
StartColumn: 15,
|
||||||
EndColumn: 34,
|
EndColumn: 34,
|
||||||
Entropy: 3.0841837,
|
Entropy: 3.0841837,
|
||||||
@@ -154,8 +154,8 @@ func TestDetect(t *testing.T) {
|
|||||||
RuleID: "discord-api-key",
|
RuleID: "discord-api-key",
|
||||||
Tags: []string{},
|
Tags: []string{},
|
||||||
Entropy: 3.7906237,
|
Entropy: 3.7906237,
|
||||||
StartLine: 0,
|
StartLine: 1,
|
||||||
EndLine: 0,
|
EndLine: 1,
|
||||||
StartColumn: 7,
|
StartColumn: 7,
|
||||||
EndColumn: 93,
|
EndColumn: 93,
|
||||||
},
|
},
|
||||||
@@ -184,8 +184,8 @@ func TestDetect(t *testing.T) {
|
|||||||
RuleID: "generic-api-key",
|
RuleID: "generic-api-key",
|
||||||
Tags: []string{},
|
Tags: []string{},
|
||||||
Entropy: 3.7906237,
|
Entropy: 3.7906237,
|
||||||
StartLine: 0,
|
StartLine: 1,
|
||||||
EndLine: 0,
|
EndLine: 1,
|
||||||
StartColumn: 22,
|
StartColumn: 22,
|
||||||
EndColumn: 93,
|
EndColumn: 93,
|
||||||
},
|
},
|
||||||
|
|||||||
+2
-3
@@ -22,7 +22,6 @@ func location(fragment Fragment, matchIndex []int) Location {
|
|||||||
end := matchIndex[1]
|
end := matchIndex[1]
|
||||||
|
|
||||||
for lineNum, pair := range fragment.newlineIndices {
|
for lineNum, pair := range fragment.newlineIndices {
|
||||||
_lineNum = lineNum
|
|
||||||
newLineByteIndex := pair[0]
|
newLineByteIndex := pair[0]
|
||||||
if prevNewLine <= start && start < newLineByteIndex {
|
if prevNewLine <= start && start < newLineByteIndex {
|
||||||
lineSet = true
|
lineSet = true
|
||||||
@@ -46,8 +45,8 @@ func location(fragment Fragment, matchIndex []int) Location {
|
|||||||
// a newline
|
// a newline
|
||||||
location.startColumn = (start - prevNewLine) + 1 // +1 because counting starts at 1
|
location.startColumn = (start - prevNewLine) + 1 // +1 because counting starts at 1
|
||||||
location.endColumn = (end - prevNewLine)
|
location.endColumn = (end - prevNewLine)
|
||||||
location.startLine = _lineNum
|
location.startLine = _lineNum + 1
|
||||||
location.endLine = _lineNum
|
location.endLine = _lineNum + 1
|
||||||
location.startLineIndex = start
|
location.startLineIndex = start
|
||||||
|
|
||||||
// search for new line byte index
|
// search for new line byte index
|
||||||
|
|||||||
Reference in new issue
Block a user