Skip to content

Commit

Permalink
fix(fn): RandExp error should not cause UI to completely fail (#7940)
Browse files Browse the repository at this point in the history
* regexp syntax varies across languages
  • Loading branch information
soundstripe authored Mar 28, 2022
1 parent ed344ff commit b825e44
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/core/plugins/samples/fn.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit b825e44

Please sign in to comment.