Skip to content

Commit

Permalink
calculate replacement offset correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
seanlinsley committed Oct 4, 2024
1 parent a5adb79 commit 25ecc68
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion logs/replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func ReplaceSecrets(input []byte, logLines []state.LogLine, filterLogSecret []st
if m.Kind == k && m.ByteStart > bytesChecked {
content = slices.Replace(content, m.ByteStart-offset, m.ByteEnd-offset, []byte(replacement)...)
bytesChecked = m.ByteEnd
offset += max(1, len(replacement)-m.ByteEnd-m.ByteStart)
offset += (m.ByteEnd - m.ByteStart) - len(replacement)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions logs/replace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ var replaceTests = []replaceTestpair{
},
{
filterLogSecret: "statement_parameter",
input: "2018-03-11 20:00:02 UTC:1.1.1.1(2):a@b:[3]:LOG: duration: 4079.697 ms execute <unnamed>: \nSELECT * FROM x WHERE y = $1 LIMIT $2\n2018-03-11 20:00:02 UTC:1.1.1.1(2):a@b:[3]:DETAIL: parameters: $1 = 'long string', $2 = '1'\n",
output: "duration: 4079.697 ms execute <unnamed>: \nSELECT * FROM x WHERE y = $1 LIMIT $2\nparameters: $1 = '[redacted]', $2 = '[redacted]'\n",
input: "2018-03-11 20:00:02 UTC:1.1.1.1(2):a@b:[3]:LOG: duration: 4079.697 ms execute <unnamed>: \nSELECT * FROM x WHERE y = $1 LIMIT $2\n2018-03-11 20:00:02 UTC:1.1.1.1(2):a@b:[3]:DETAIL: parameters: $1 = 'long string', $2 = '1', $3 = 'long string'\n",
output: "duration: 4079.697 ms execute <unnamed>: \nSELECT * FROM x WHERE y = $1 LIMIT $2\nparameters: $1 = '[redacted]', $2 = '[redacted]', $3 = '[redacted]'\n",
},
{
filterLogSecret: "none",
Expand Down

0 comments on commit 25ecc68

Please sign in to comment.