Skip to content

Commit 0bb7bb4

Browse files
committed
Extend RX operator test cases with re_groups
See owasp-modsecurity/ModSecurity#2007. Adds "re_groups" field to RX (regular expression) test cases, allowing not only binary match-no match test, but also verifying that capturing groups are correct. This obviously needs support from the test case runner, but the change is backward-compatible in the way that these new fields can be ignored.
1 parent e6b03e4 commit 0bb7bb4

File tree

1 file changed

+91
-2
lines changed

1 file changed

+91
-2
lines changed

operators/rx.json

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,16 @@
3939
"input" : "abcdefghi",
4040
"type" : "op",
4141
"ret" : 1,
42-
"name" : "rx"
42+
"name" : "rx",
43+
"re_groups": ["def"]
4344
},
4445
{
4546
"param" : "ghi",
4647
"input" : "abcdefghi",
4748
"name" : "rx",
4849
"type" : "op",
49-
"ret" : 1
50+
"ret" : 1,
51+
"re_groups": ["ghi"]
5052
},
5153
{
5254
"ret" : 0,
@@ -61,5 +63,92 @@
6163
"name" : "rx",
6264
"param" : "(?i:(sleep\\((\\s*?)(\\d*?)(\\s*?)\\)|benchmark\\((.*?)\\,(.*?)\\)))",
6365
"input" : "SELECT pg_sleep(10);"
66+
},
67+
{
68+
"type" : "op",
69+
"name" : "rx",
70+
"param" : "(abc)(def)",
71+
"input" : "abcdef",
72+
"ret" : 1,
73+
"re_groups": ["abcdef", "abc", "def"]
74+
},
75+
{
76+
"type" : "op",
77+
"name" : "rx",
78+
"param" : "(a|b|1|2)(a|b|1|2)",
79+
"input" : "a2b1",
80+
"ret" : 1,
81+
"re_groups": ["a2", "a", "2"]
82+
},
83+
{
84+
"type" : "op",
85+
"name" : "rx",
86+
"param" : "<\\?(?!xml)",
87+
"input" : "<?php",
88+
"ret" : 1,
89+
"re_groups": ["<?"]
90+
},
91+
{
92+
"type" : "op",
93+
"name" : "rx",
94+
"param" : "<\\?(?!xml)",
95+
"input" : "<?xml",
96+
"ret" : 0
97+
},
98+
{
99+
"type" : "op",
100+
"name" : "rx",
101+
"param" : "abc\ndef",
102+
"input" : "abc\ndef",
103+
"ret" : 1,
104+
"re_groups": ["abc\ndef"]
105+
},
106+
{
107+
"type" : "op",
108+
"name" : "rx",
109+
"param" : "[a-z]\n",
110+
"input" : "a\nb\nc\n",
111+
"ret" : 1,
112+
"re_groups": ["a\n"]
113+
},
114+
{
115+
"type" : "op",
116+
"name" : "rx",
117+
"param" : "[a-z]*",
118+
"input" : "abkjgdsgk",
119+
"ret" : 1,
120+
"re_groups": ["abkjgdsgk"]
121+
},
122+
{
123+
"type" : "op",
124+
"name" : "rx",
125+
"param" : "([a-z]*)",
126+
"input" : "",
127+
"ret" : 1,
128+
"re_groups": ["", ""]
129+
},
130+
{
131+
"type" : "op",
132+
"name" : "rx",
133+
"param" : "[a-z]*",
134+
"input" : "aaa0bbb",
135+
"ret" : 1,
136+
"re_groups": ["aaa"]
137+
},
138+
{
139+
"type" : "op",
140+
"name" : "rx",
141+
"param" : "[a-z]*",
142+
"input" : "aaa00bbb",
143+
"ret" : 1,
144+
"re_groups": ["aaa"]
145+
},
146+
{
147+
"type" : "op",
148+
"name" : "rx",
149+
"param" : "(a)(b?)(c)",
150+
"input" : "ac",
151+
"ret" : 1,
152+
"re_groups": ["ac", "a", "", "c"]
64153
}
65154
]

0 commit comments

Comments
 (0)