-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathregex_rules_test.js
More file actions
37 lines (34 loc) · 877 Bytes
/
regex_rules_test.js
File metadata and controls
37 lines (34 loc) · 877 Bytes
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
var elements = require('./regex_rules.json')
var print = function (m1, m2) {
console.log(m1, m2)
}
var context = {
setVariable: function (s, v) {
console.log(s, v)
},
proxyRequest: {
url: 'http://localhost/bla/x=create function foobar returns'
}
}
var block = function (haystack, filters) {
filters.some(function (jsonRegex) {
// Create a regex from the json string.
// print('regex',jsonRegex.rule);
var f = new RegExp(jsonRegex.rule, jsonRegex.flags)
// print('regex',f);
var hit = f.exec(haystack)
if (hit) {
print('found', hit[0])
context.setVariable('FILTER.block', true)
return true
}
})
}
elements.forEach(function (element) {
var filters = element.filters
if (element.element === 'QueryParam') {
if (block(decodeURIComponent(context.proxyRequest.url), filters)) {
return
}
}
})