From b825e440770d9328996a116784cb77b05ab24c6c Mon Sep 17 00:00:00 2001 From: Steven James Date: Mon, 28 Mar 2022 19:29:01 -0400 Subject: [PATCH] fix(fn): RandExp error should not cause UI to completely fail (#7940) * regexp syntax varies across languages --- src/core/plugins/samples/fn.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/core/plugins/samples/fn.js b/src/core/plugins/samples/fn.js index d66b504e1b0..a6988d2c1f6 100644 --- a/src/core/plugins/samples/fn.js +++ b/src/core/plugins/samples/fn.js @@ -6,8 +6,13 @@ import { objectify, isFunc, normalizeArray, deeplyStripKey } from "core/utils" import memoizeN from "../../../helpers/memoizeN" const generateStringFromRegex = (pattern) => { - const randexp = new RandExp(pattern) - return randexp.gen() + try { + const randexp = new RandExp(pattern) + return randexp.gen() + } catch (e) { + // Invalid regex should not cause a crash (regex syntax varies across languages) + return "string" + } } const primitives = {