From 256631d6be4b2b40ae660a7e9052cde07a3da18c Mon Sep 17 00:00:00 2001 From: Shinigami Date: Thu, 16 Mar 2023 09:45:48 +0100 Subject: fix(random): prevent infinite do-while (#1938) --- src/modules/random/index.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/modules') diff --git a/src/modules/random/index.ts b/src/modules/random/index.ts index a2847bbc..b35b7c87 100644 --- a/src/modules/random/index.ts +++ b/src/modules/random/index.ts @@ -125,6 +125,8 @@ export class RandomModule { ]; let result: string; + let iteration = 0; + do { // randomly pick from the many faker methods that can generate words const randomWordMethod = this.faker.helpers.arrayElement(wordMethods); @@ -133,6 +135,14 @@ export class RandomModule { result = randomWordMethod(); } catch { // catch missing locale data potentially required by randomWordMethod + iteration++; + + if (iteration > 100) { + throw new FakerError( + 'No matching word data available for the current locale' + ); + } + continue; } } while (!result || bannedChars.some((char) => result.includes(char))); -- cgit v1.2.3