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' ;
1816import type { Config } from './Config.js' ;
1917import { 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 ;
3028const 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 ;
3430const 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
3741const 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