From 88899317bc50d05ced5abe6cd1abd0b3a2f5ff58 Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Mon, 22 Jul 2024 14:21:56 +0200 Subject: [PATCH] Fix license.ts#replaceLicenseDefaults --- src/controller/license.ts | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/controller/license.ts b/src/controller/license.ts index 4780e1d..781604f 100644 --- a/src/controller/license.ts +++ b/src/controller/license.ts @@ -29,13 +29,26 @@ export const generateRandom = () => { } export const replaceLicenseDefaults = (defaultKey: string) => { - return defaultKey.replace(/N/g, () => String(Math.floor(Math.random() * 10))) - .replace(/C/g, () => generateCharacter()) - .replace(/L/g, () => String.fromCharCode(Math.floor(Math.random() * 26) + 97)) - .replace(/U/g, () => String.fromCharCode(Math.floor(Math.random() * 26) + 65)) - .replace(/S/g, () => generateSpecialCharacter()) - .replace(/A/g, () => generateAlphaNumeric()) - .replace(/R/g, () => generateRandom()); + return defaultKey.split('').map(char => { + switch (char) { + case 'N': + return String(Math.floor(Math.random() * 10)); + case 'C': + return generateCharacter(); + case 'L': + return String.fromCharCode(Math.floor(Math.random() * 26) + 97); + case 'U': + return String.fromCharCode(Math.floor(Math.random() * 26) + 65); + case 'S': + return generateSpecialCharacter(); + case 'A': + return generateAlphaNumeric(); + case 'R': + return generateRandom(); + default: + return char; + } + }).join(''); } export const checkLicenseConfiguration = async (access: IProject, config: ILicense) => {