@@ -22,31 +22,33 @@ def extract_js(file_path):
22
22
23
23
return js_from_html
24
24
25
- def extract_regexes (json_tempfile ):
26
- output = subprocess .run ([os .path .join (os .getcwd (), 'extract-regexes.pl' ), json_tempfile .name ],
25
+ def extract_regexes (json_tempfile , file_path ):
26
+ output = subprocess .run (
27
+ [os .path .join (os .environ ['VULN_REGEX_DETECTOR_ROOT' ], 'src/extract/extract-regexes.pl' ),
28
+ json_tempfile .name ],
27
29
capture_output = True , text = True )
28
- return json .loads (output .stdout )
30
+ output_json = json .loads (output .stdout )
31
+ output_json ['file' ] = file_path
32
+ return json .dumps (output_json )
33
+
29
34
30
35
file_path = sys .argv [1 ]
31
36
js_from_html = extract_js (file_path )
32
37
33
38
# create temp-js-content.js based on the location of extract-regexes.pl
34
- js_tempfile = tempfile .NamedTemporaryFile (suffix = '.js' , mode = 'w+t' )
39
+ js_tempfile = tempfile .NamedTemporaryFile (suffix = '.js' , mode = 'w+t' , delete = False )
35
40
js_tempfile .writelines (js_from_html )
36
- js_tempfile .seek ( 0 )
41
+ js_tempfile .close ( )
37
42
38
43
# create temp json file to pass to the meta-program
39
- json_tempfile = tempfile .NamedTemporaryFile (suffix = '.json' , mode = 'w+t' )
44
+ json_tempfile = tempfile .NamedTemporaryFile (suffix = '.json' , mode = 'w+t' , delete = False )
40
45
json_tempfile .writelines (json .dumps ({"file" : js_tempfile .name , "language" : "javascript" }))
41
- json_tempfile .seek ( 0 )
46
+ json_tempfile .close ( )
42
47
43
48
# call the meta-program
44
- output_json = extract_regexes (json_tempfile )
45
- output_json ['file' ] = file_path
46
- return_string = json .dumps (output_json )
47
- print (return_string , end = '' )
49
+ print (extract_regexes (json_tempfile , file_path ), end = '' )
48
50
49
51
# delete the temp js and json file
50
- js_tempfile . close ( )
51
- json_tempfile . close ( )
52
+ os . remove ( js_tempfile . name )
53
+ os . remove ( json_tempfile . name )
52
54
0 commit comments