@@ -97,12 +97,24 @@ def analyze_line(
97
97
self ._analyzed_files .add (filename )
98
98
file_content = self .read_file (filename )
99
99
if file_content :
100
- output .update (
101
- super ().analyze_line (
102
- filename = filename , line = file_content , line_number = 1 ,
103
- context = context , raw_context = raw_context , ** kwargs ,
104
- ),
100
+ found_secrets = super ().analyze_line (
101
+ filename = filename , line = file_content , line_number = 1 ,
102
+ context = context , raw_context = raw_context , ** kwargs ,
105
103
)
104
+ updated_secrets = set ()
105
+ for sec in found_secrets :
106
+ secret_val = sec .secret_value or ''
107
+ line_number = self .find_line_number (file_content , secret_val )
108
+ updated_secrets .add (
109
+ PotentialSecret (
110
+ type = self .secret_type ,
111
+ filename = sec .filename ,
112
+ secret = secret_val ,
113
+ line_number = line_number ,
114
+ is_verified = sec .is_verified ,
115
+ ),
116
+ )
117
+ output .update (updated_secrets )
106
118
return output
107
119
108
120
def analyze_string (self , string : str ) -> Generator [str , None , None ]:
@@ -129,3 +141,15 @@ def get_file_size(self, file_path: str) -> int:
129
141
return os .path .getsize (file_path )
130
142
except Exception :
131
143
return - 1
144
+
145
+ def find_line_number (
146
+ self , file_content : str , substring : str , default_line_number : int = 1 ,
147
+ ) -> int :
148
+ if len (substring ) == 0 :
149
+ return default_line_number
150
+ lines = file_content .splitlines ()
151
+
152
+ for line_number , line in enumerate (lines , start = 1 ):
153
+ if substring in line :
154
+ return line_number
155
+ return default_line_number
0 commit comments