We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 48114ed + 878da68 commit 747aa82Copy full SHA for 747aa82
public/app/core/specs/kbn.test.ts
@@ -0,0 +1,15 @@
1
+import kbn from '../utils/kbn';
2
+
3
+describe('stringToJsRegex', () => {
4
+ it('should parse the valid regex value', () => {
5
+ const output = kbn.stringToJsRegex('/validRegexp/');
6
+ expect(output).toBeInstanceOf(RegExp);
7
+ });
8
9
+ it('should throw error on invalid regex value', () => {
10
+ const input = '/etc/hostname';
11
+ expect(() => {
12
+ kbn.stringToJsRegex(input);
13
+ }).toThrow();
14
15
+});
public/app/core/utils/kbn.ts
@@ -234,6 +234,11 @@ kbn.stringToJsRegex = str => {
234
}
235
236
const match = str.match(new RegExp('^/(.*?)/(g?i?m?y?)$'));
237
238
+ if (!match) {
239
+ throw new Error(`'${str}' is not a valid regular expression.`);
240
+ }
241
242
return new RegExp(match[1], match[2]);
243
};
244
0 commit comments