소스 검색

remove color formatting when #1042 is encountered (#1050)

Zachary Rice 3 년 전
부모
커밋
d805fb9144
1개의 변경된 파일14개의 추가작업 그리고 1개의 파일을 삭제
  1. 14 1
      detect/utils.go

+ 14 - 1
detect/utils.go

@@ -102,6 +102,13 @@ func printFinding(f report.Finding) {
 	matchInLineIDX := strings.Index(f.Line, f.Match)
 	matchInLineIDX := strings.Index(f.Line, f.Match)
 	secretInMatchIdx := strings.Index(f.Match, f.Secret)
 	secretInMatchIdx := strings.Index(f.Match, f.Secret)
 
 
+	skipColor := false
+
+	if matchInLineIDX == -1 {
+		skipColor = true
+		matchInLineIDX = 0
+	}
+
 	start := f.Line[0:matchInLineIDX]
 	start := f.Line[0:matchInLineIDX]
 	startMatchIdx := 0
 	startMatchIdx := 0
 	if matchInLineIDX > 20 {
 	if matchInLineIDX > 20 {
@@ -127,7 +134,13 @@ func printFinding(f report.Finding) {
 	}
 	}
 
 
 	finding := fmt.Sprintf("%s%s%s%s%s\n", strings.TrimPrefix(strings.TrimLeft(start, " "), "\n"), matchBeginning, secret, matchEnd, lineEnd)
 	finding := fmt.Sprintf("%s%s%s%s%s\n", strings.TrimPrefix(strings.TrimLeft(start, " "), "\n"), matchBeginning, secret, matchEnd, lineEnd)
-	fmt.Printf("%-12s %s", "Finding:", finding)
+
+	if skipColor {
+		fmt.Printf("%-12s %s\n", "Finding:", f.Match)
+	} else {
+		fmt.Printf("%-12s %s", "Finding:", finding)
+	}
+
 	fmt.Printf("%-12s %s\n", "Secret:", secret)
 	fmt.Printf("%-12s %s\n", "Secret:", secret)
 	fmt.Printf("%-12s %s\n", "RuleID:", f.RuleID)
 	fmt.Printf("%-12s %s\n", "RuleID:", f.RuleID)
 	fmt.Printf("%-12s %f\n", "Entropy:", f.Entropy)
 	fmt.Printf("%-12s %f\n", "Entropy:", f.Entropy)