Skip to content

Commit e8ed1b4

Browse files
committed
Fix tempfile issue and absolute path issue (now html extractor can be run from any directory)
1 parent a5404d5 commit e8ed1b4

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/extract/src/html/extract-regexps-html.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,33 @@ def extract_js(file_path):
2222

2323
return js_from_html
2424

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],
2729
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+
2934

3035
file_path = sys.argv[1]
3136
js_from_html = extract_js(file_path)
3237

3338
# 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)
3540
js_tempfile.writelines(js_from_html)
36-
js_tempfile.seek(0)
41+
js_tempfile.close()
3742

3843
# 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)
4045
json_tempfile.writelines(json.dumps({"file": js_tempfile.name, "language": "javascript"}))
41-
json_tempfile.seek(0)
46+
json_tempfile.close()
4247

4348
# 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 = '')
4850

4951
# 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)
5254

0 commit comments

Comments
 (0)