-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregex.js
More file actions
23 lines (20 loc) · 712 Bytes
/
regex.js
File metadata and controls
23 lines (20 loc) · 712 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import safe from "safe-regex";
import fs from "fs";
export default function regex_callback(request, response) {
const regex = request.query?.regex;
let content = "";
if (regex) {
content = fs.readFileSync("public/regex.html", "utf8");
// Convert exec to execFile
const result = safe(regex) ? "SAFE" : "NOT SAFE";
content = content.replace(">", "> <code style=\"color: darkred;\">" + regex + "</code> is " + result);
response.send(content);
} else {
try {
content = fs.readFileSync("public/regex.html", "utf8");
} catch (e) {
console.log("Error:", e.stack);
}
response.send(content);
}
}