fix(util) getRegExp: multiple dots

This commit is contained in:
coderaiser 2020-04-13 18:35:26 +03:00
parent 545b5a5135
commit 798d974677
2 changed files with 9 additions and 2 deletions

View file

@ -16,8 +16,8 @@ module.exports.escapeRegExp = (str) => {
*/
module.exports.getRegExp = (wildcard) => {
const escaped = '^' + wildcard // search from start of line
.replace('.', '\\.')
.replace('*', '.*')
.replace(/\./g, '\\.')
.replace(/\*/g, '.*')
.replace('?', '.?') + '$'; // search to end of line
return RegExp(escaped);

View file

@ -93,6 +93,13 @@ test('util: getRegExp', (t) => {
t.end();
});
test('util: getRegExp: dots', (t) => {
const reg = getRegExp('h.*el?o.*');
t.deepEqual(reg, /^h\..*el.?o\..*$/, 'should return regexp');
t.end();
});
test('util: getRegExp: no', (t) => {
const reg = getRegExp('');