mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
fix(util) getRegExp: multiple dots
This commit is contained in:
parent
545b5a5135
commit
798d974677
2 changed files with 9 additions and 2 deletions
|
|
@ -16,8 +16,8 @@ module.exports.escapeRegExp = (str) => {
|
||||||
*/
|
*/
|
||||||
module.exports.getRegExp = (wildcard) => {
|
module.exports.getRegExp = (wildcard) => {
|
||||||
const escaped = '^' + wildcard // search from start of line
|
const escaped = '^' + wildcard // search from start of line
|
||||||
.replace('.', '\\.')
|
.replace(/\./g, '\\.')
|
||||||
.replace('*', '.*')
|
.replace(/\*/g, '.*')
|
||||||
.replace('?', '.?') + '$'; // search to end of line
|
.replace('?', '.?') + '$'; // search to end of line
|
||||||
|
|
||||||
return RegExp(escaped);
|
return RegExp(escaped);
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,13 @@ test('util: getRegExp', (t) => {
|
||||||
t.end();
|
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) => {
|
test('util: getRegExp: no', (t) => {
|
||||||
const reg = getRegExp('');
|
const reg = getRegExp('');
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue