diff --git a/detect/detect_test.go b/detect/detect_test.go index 1060cefd..5ad9006a 100644 --- a/detect/detect_test.go +++ b/detect/detect_test.go @@ -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, @@ -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, @@ -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, }, @@ -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, }, diff --git a/detect/location.go b/detect/location.go index a88557c0..845dbd9f 100644 --- a/detect/location.go +++ b/detect/location.go @@ -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 @@ -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