Skip to content

Commit

Permalink
Refactor FragmentLineOffset to match multiline secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
mcastorina committed Aug 9, 2023
1 parent 2d2595a commit 7e278d8
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,17 +595,17 @@ func SupportsLineNumbers(sourceType sourcespb.SourceType) bool {

// FragmentLineOffset sets the line number for a provided source chunk with a given detector result.
func FragmentLineOffset(chunk *sources.Chunk, result *detectors.Result) (int64, bool) {
lines := bytes.Split(chunk.Data, []byte("\n"))
for i, line := range lines {
if bytes.Contains(line, result.Raw) {
// if the line contains the ignore tag, we should ignore the result
if bytes.Contains(line, []byte(ignoreTag)) {
return int64(i), true
}
return int64(i), false
}
before, after, found := bytes.Cut(chunk.Data, result.Raw)
if !found {
return 0, false
}
lineNumber := int64(len(bytes.Split(before, []byte("\n")))) - 1
// if the line contains the ignore tag, we should ignore the result
endLine := bytes.Index(after, []byte("\n"))
if endLine != -1 && bytes.Contains(after[:endLine], []byte(ignoreTag)) {
return lineNumber, true
}
return 0, false
return lineNumber, false
}

// FragmentFirstLine returns the first line number of a fragment along with a pointer to the value to update in the
Expand Down

0 comments on commit 7e278d8

Please sign in to comment.