scan. glob to regex (#14063)

* scan. glob to regex

* lint
This commit is contained in:
Barış Uşaklı
2026-03-05 16:01:03 -05:00
committed by GitHub
parent 5d1a8a11fd
commit 7d50baecf0
6 changed files with 44 additions and 30 deletions

View File

@@ -1,7 +1,6 @@
'use strict';
const helpers = module.exports;
const utils = require('../../utils');
helpers.noop = function () {};
@@ -50,20 +49,3 @@ helpers.valueToString = function (value) {
return String(value);
};
helpers.buildMatchQuery = function (match) {
let _match = match;
if (match.startsWith('*')) {
_match = _match.substring(1);
}
if (match.endsWith('*')) {
_match = _match.substring(0, _match.length - 1);
}
_match = utils.escapeRegexChars(_match);
if (!match.startsWith('*')) {
_match = `^${_match}`;
}
if (!match.endsWith('*')) {
_match += '$';
}
return _match;
};

View File

@@ -1,7 +1,7 @@
'use strict';
module.exports = function (module) {
const helpers = require('./helpers');
const dbHelpers = require('../helpers');
module.flushdb = async function () {
await module.client.dropDatabase();
};
@@ -39,7 +39,7 @@ module.exports = function (module) {
};
module.scan = async function (params) {
const match = helpers.buildMatchQuery(params.match);
const match = dbHelpers.globToRegex(params.match);
return await module.client.collection('objects').distinct(
'_key', { _key: { $regex: new RegExp(match) } }
);

View File

@@ -543,7 +543,7 @@ module.exports = function (module) {
project.score = 1;
}
const match = helpers.buildMatchQuery(params.match);
const match = dbHelpers.globToRegex(params.match);
let regex;
try {
regex = new RegExp(match);