Skip to content

Find, verify, and analyze leaked credentials

fix(gitparse): don't trim filename (#2201)

Richard Gomeze72fdb62e47a
diff --git a/pkg/gitparse/gitparse.go b/pkg/gitparse/gitparse.go
index 39a72d399..f7b912448 100644
--- a/pkg/gitparse/gitparse.go
+++ b/pkg/gitparse/gitparse.go
@@ -608,7 +608,7 @@ func pathFromBinaryLine(line []byte) string {
return ""
}
bRaw := sbytes[1]
- return strings.TrimSpace(string(bRaw[:len(bRaw)-7])) // drop the "b/" and " differ"
+ return string(bRaw[:len(bRaw)-8]) // drop the "b/" and " differ\n"
}
// --- a/internal/addrs/move_endpoint_module.go
diff --git a/pkg/gitparse/gitparse_test.go b/pkg/gitparse/gitparse_test.go
index 02fbbd209..33d6e4483 100644
--- a/pkg/gitparse/gitparse_test.go
+++ b/pkg/gitparse/gitparse_test.go
@@ -195,6 +195,10 @@ func TestLineChecks(t *testing.T) {
MessageEndLine,
[]byte("diff --git a/pkg/sources/source_unit.go b/pkg/sources/source_unit.go"),
},
+ {
+ MessageEndLine,
+ []byte("diff --git a/ Lunch and Learn - HCDiag.pdf b/ Lunch and Learn - HCDiag.pdf"),
+ },
{
BinaryFileLine,
[]byte("diff --git a/pkg/decoders/utf16_test.go b/pkg/decoders/utf16_test.go"),
@@ -292,6 +296,10 @@ func TestLineChecks(t *testing.T) {
IndexLine,
[]byte("Binary files /dev/null and b/plugin.sig differ"),
},
+ {
+ IndexLine,
+ []byte("Binary files /dev/null and b/ Lunch and Learn - HCDiag.pdf differ"),
+ },
},
fails: []testCaseLine{
{
@@ -648,10 +656,16 @@ Co-authored-by: Sergey Beryozkin <[email protected]>
}
func TestBinaryPathParse(t *testing.T) {
- filename := pathFromBinaryLine([]byte("Binary files /dev/null and b/plugin.sig differ"))
- expected := "plugin.sig"
- if filename != expected {
- t.Errorf("Expected: %s, Got: %s", expected, filename)
+ cases := map[string]string{
+ "Binary files /dev/null and b/plugin.sig differ\n": "plugin.sig",
+ "Binary files /dev/null and b/ Lunch and Learn - HCDiag.pdf differ\n": " Lunch and Learn - HCDiag.pdf",
+ }
+
+ for name, expected := range cases {
+ filename := pathFromBinaryLine([]byte(name))
+ if filename != expected {
+ t.Errorf("Expected: %s, Got: %s", expected, filename)
+ }
}
}