Skip to content

Commit 4d5e323

Browse files
committed
add regex check fro validator
1 parent e1f9b68 commit 4d5e323

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/config/validateConfig.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
// You should have received a copy of the GNU Affero General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16-
17-
import { isRegExp } from 'util/types';
1816
import type { Config } from './Config.js';
1917
import { SUPPORTED_VALIDATORS } from '../validation/Validation.js';
2018

@@ -29,10 +27,16 @@ const isNumber: ConfigValidator = (label: string, v: unknown) =>
2927
typeof v !== 'number' ? `${label} must be a number` : undefined;
3028
const isString: ConfigValidator = (label: string, v: unknown) =>
3129
typeof v !== 'string' ? `${label} must be a string` : undefined;
32-
const isRegexp: ConfigValidator = (label: string, v: unknown) =>
33-
!isRegExp(v) ? `${label} is not a valid JavaScript Regular Expression` : undefined;
3430
const isNotEmptyString: ConfigValidator = (label: string, v: unknown) =>
3531
typeof v === 'string' && v.length === 0 ? `${label} cannot be an empty string` : undefined;
32+
const isRegexp: ConfigValidator = (label: string, v: unknown) => {
33+
try {
34+
const _ = RegExp(v as string);
35+
return;
36+
} catch {
37+
return `${label} is not a valid JavaScript Regular Expression`
38+
}
39+
}
3640

3741
const isOneOf = (label: string, vs: unknown[], v: unknown) =>
3842
!vs.includes(v) ? `${label} must be ${vs.join(' or ')}` : undefined;
@@ -199,6 +203,7 @@ const checkAlgorithm = (algorithm: Config.Options['algorithm'], sourceColumns: s
199203
check =
200204
isObject('[algorithm].salt.value', algorithm.salt.value) ||
201205
isOptional('[algorithm].salt.validator_regex', algorithm.salt.validator_regex, isString) ||
206+
isOptional('[algorithm].salt.validator_regex', algorithm.salt!.validator_regex, isRegexp) ||
202207
isOptional('[algorithm].salt.value.win32', algorithm.salt.value!.win32, isString) ||
203208
isOptional('[algorithm].salt.value.darwin', algorithm.salt.value!.darwin, isString) ||
204209
isOptional('[algorithm].salt.value.linux', algorithm.salt.value!.linux, isString);

0 commit comments

Comments
 (0)