-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
regen-mistakes.js
51 lines (39 loc) · 1.06 KB
/
regen-mistakes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
let patterns = require('./data/pywhat_regexes.json');
let fs = require('fs');
patterns = patterns.filter(ident => {
if(/public\s+key/i.test(ident.Name)) {
return false;
}
if(/(private|secret)(\s+access)?\s+key/i.test(ident.Name)) {
return true;
}
for(let tag of ident.Tags) {
if(/credentials/i.test(tag) && ident.Rarity > 0.2) {
return true;
}
if(/key|bounty/i.test(tag)) {
return true;
}
}
return false;
});
let linear_mistakes = [];
for(let mistake of patterns) {
let re = mistake.Regex.replace(/\^|\$/g, '\\b').replace(/\(\?P(<\w+>)/ig, '(?$1');
try {
test_re(re);
} catch {
console.log("Error with", mistake.Name);
continue;
}
linear_mistakes.push(mistake.Name, re);
}
fs.writeFileSync("./src/lib/mistakes.json", JSON.stringify(linear_mistakes, null, 4));
function test_re(re) {
let flags = '';
if(re.startsWith('(?i)')) {
flags = 'i';
re = re.slice('(?i)'.length);
}
new RegExp(re, flags);
}