3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

Fix crash from passing an invalid regex source to TRegex validation function

This commit is contained in:
Dragory 2021-04-13 23:50:39 +03:00
parent c03e7240b4
commit a558af1038
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1

View file

@ -27,7 +27,15 @@ export const TRegex = new t.Type<RegExp, string>(
(s): s is RegExp => s instanceof RegExp,
(from, to) =>
either.chain(t.string.validate(from, to), s => {
return t.success(inputPatternToRegExp(s));
try {
return t.success(inputPatternToRegExp(s));
} catch (err) {
if (err instanceof InvalidRegexError) {
return t.failure(s, [], err.message);
}
throw err;
}
}),
s => `/${s.source}/${s.flags}`,
);