Skip to content

Find, verify, and analyze leaked credentials

[bug] - Fix the starting index value for plus line check. (#734)

ahrav20cdcbc9709f
diff --git a/pkg/gitparse/gitparse.go b/pkg/gitparse/gitparse.go
index 42e67c3a7..925da99ce 100644
--- a/pkg/gitparse/gitparse.go
+++ b/pkg/gitparse/gitparse.go
@@ -218,7 +218,7 @@ func isModeLine(line []byte) bool {
// --- a/internal/addrs/move_endpoint_module.go
func isMinusFileLine(line []byte) bool {
- if len(line) > 3 && bytes.Equal(line[:3], []byte("---")) {
+ if len(line) >= 6 && bytes.Equal(line[:3], []byte("---")) {
return true
}
return false
@@ -226,7 +226,7 @@ func isMinusFileLine(line []byte) bool {
// +++ b/internal/addrs/move_endpoint_module.go
func isPlusFileLine(line []byte) bool {
- if len(line) > 3 && bytes.Equal(line[:3], []byte("+++")) {
+ if len(line) >= 6 && bytes.Equal(line[:3], []byte("+++")) {
return true
}
return false
diff --git a/pkg/gitparse/gitparse_test.go b/pkg/gitparse/gitparse_test.go
index ab81d45e1..827299e8f 100644
--- a/pkg/gitparse/gitparse_test.go
+++ b/pkg/gitparse/gitparse_test.go
@@ -6,7 +6,7 @@ import (
type testCase struct {
pass []byte
- fail []byte
+ fails [][]byte
function func([]byte) bool
}
@@ -14,47 +14,46 @@ func TestIsIndexLine(t *testing.T) {
tests := map[string]testCase{
"indexLine": {
pass: []byte("index 1ed6fbee1..aea1e643a 100644"),
- fail: []byte("notcorrect"),
+ fails: [][]byte{[]byte("notcorrect")},
function: isIndexLine,
},
"modeLine": {
pass: []byte("new file mode 100644"),
- fail: []byte("notcorrect"),
+ fails: [][]byte{[]byte("notcorrect")},
function: isModeLine,
},
"minusFileLine": {
pass: []byte("--- a/internal/addrs/move_endpoint_module.go"),
- fail: []byte("notcorrect"),
+ fails: [][]byte{[]byte("notcorrect"), []byte("--- s"), []byte("short")},
function: isMinusFileLine,
},
"plusFileLine": {
pass: []byte("+++ b/internal/addrs/move_endpoint_module.go"),
- fail: []byte("notcorrect"),
+ fails: [][]byte{[]byte("notcorrect"), []byte("+++ s"), []byte("short")},
function: isPlusFileLine,
},
"plusDiffLine": {
pass: []byte("+fmt.Println"),
- fail: []byte("notcorrect"),
+ fails: [][]byte{[]byte("notcorrect")},
function: isPlusDiffLine,
},
"minusDiffLine": {
pass: []byte("-fmt.Println"),
- fail: []byte("notcorrect"),
function: isMinusDiffLine,
},
"messageLine": {
pass: []byte(" committed"),
- fail: []byte("notcorrect"),
+ fails: [][]byte{[]byte("notcorrect")},
function: isMessageLine,
},
"binaryLine": {
pass: []byte("Binary files /dev/null and b/plugin.sig differ"),
- fail: []byte("notcorrect"),
+ fails: [][]byte{[]byte("notcorrect")},
function: isBinaryLine,
},
"lineNumberLine": {
pass: []byte("@@ -298 +298 @@ func maxRetryErrorHandler(resp *http.Response, err error, numTries int)"),
- fail: []byte("notcorrect"),
+ fails: [][]byte{[]byte("notcorrect")},
function: isLineNumberDiffLine,
},
}
@@ -63,8 +62,10 @@ func TestIsIndexLine(t *testing.T) {
if !test.function(test.pass) {
t.Errorf("%s: Parser did not recognize correct line.", name)
}
- if test.function(test.fail) {
- t.Errorf("%s: Parser matched an incorrect line.", name)
+ for _, fail := range test.fails {
+ if test.function(fail) {
+ t.Errorf("%s: Parser did not recognize incorrect line.", name)
+ }
}
}
}