Skip to content

Commit 747aa82

Browse files
committed
Merge branch 'SamuelToh-11780_wrong_repexp_in_series'
2 parents 48114ed + 878da68 commit 747aa82

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

public/app/core/specs/kbn.test.ts

+15
Original file line numberDiff line numberDiff line change
@@ -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

+5
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,11 @@ kbn.stringToJsRegex = str => {
234234
}
235235

236236
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+
237242
return new RegExp(match[1], match[2]);
238243
};
239244

0 commit comments

Comments
 (0)