Skip to content

Commit

Permalink
fixing a location off by one edge case for --no-git (#812)
Browse files Browse the repository at this point in the history
  • Loading branch information
zricethezav committed Mar 22, 2022
1 parent 31ff867 commit ba9e089
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
16 changes: 8 additions & 8 deletions detect/detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ func TestDetect(t *testing.T) {
File: "tmp.go",
RuleID: "pypi-upload-token",
Tags: []string{"key", "pypi"},
StartLine: 0,
EndLine: 0,
StartLine: 1,
EndLine: 1,
StartColumn: 1,
EndColumn: 86,
Entropy: 1.9606875,
Expand All @@ -106,8 +106,8 @@ func TestDetect(t *testing.T) {
File: "tmp.go",
RuleID: "aws-access-key",
Tags: []string{"key", "AWS"},
StartLine: 0,
EndLine: 0,
StartLine: 1,
EndLine: 1,
StartColumn: 15,
EndColumn: 34,
Entropy: 3.0841837,
Expand Down Expand Up @@ -154,8 +154,8 @@ func TestDetect(t *testing.T) {
RuleID: "discord-api-key",
Tags: []string{},
Entropy: 3.7906237,
StartLine: 0,
EndLine: 0,
StartLine: 1,
EndLine: 1,
StartColumn: 7,
EndColumn: 93,
},
Expand Down Expand Up @@ -184,8 +184,8 @@ func TestDetect(t *testing.T) {
RuleID: "generic-api-key",
Tags: []string{},
Entropy: 3.7906237,
StartLine: 0,
EndLine: 0,
StartLine: 1,
EndLine: 1,
StartColumn: 22,
EndColumn: 93,
},
Expand Down
5 changes: 2 additions & 3 deletions detect/location.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func location(fragment Fragment, matchIndex []int) Location {
end := matchIndex[1]

for lineNum, pair := range fragment.newlineIndices {
_lineNum = lineNum
newLineByteIndex := pair[0]
if prevNewLine <= start && start < newLineByteIndex {
lineSet = true
Expand All @@ -46,8 +45,8 @@ func location(fragment Fragment, matchIndex []int) Location {
// a newline
location.startColumn = (start - prevNewLine) + 1 // +1 because counting starts at 1
location.endColumn = (end - prevNewLine)
location.startLine = _lineNum
location.endLine = _lineNum
location.startLine = _lineNum + 1
location.endLine = _lineNum + 1
location.startLineIndex = start

// search for new line byte index
Expand Down

0 comments on commit ba9e089

Please sign in to comment.