From 819e102fe1e5bca438f44a92a50d106ddda61f3f Mon Sep 17 00:00:00 2001 From: Duck McSouls Date: Tue, 27 Sep 2022 00:01:21 +1000 Subject: [PATCH] CCT: no special characters in file names of Coding Contracts Fixes #4067. The file name of a Coding Contract follows the format contract-xxx-rewardName.cct. The part `xxx` means a sequence of random decimal digits. The part `rewardName` can be an empty string if the player is not part of any faction nor is working for a company. However, if the player is working for a company or faction whose name has a special character, then the special character would also appear in the generated file name. We only want alphanumeric characters throughout the whole file name. --- src/CodingContractGenerator.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CodingContractGenerator.ts b/src/CodingContractGenerator.ts index 9ec41ca0c..9f913ed48 100644 --- a/src/CodingContractGenerator.ts +++ b/src/CodingContractGenerator.ts @@ -191,7 +191,8 @@ function getRandomFilename(server: BaseServer, reward: ICodingContractReward): s } if (reward.name) { - contractFn += `-${reward.name.replace(/\s/g, "")}`; + // Only alphanumeric characters in the reward name. + contractFn += `-${reward.name.replace(/[^a-zA-Z0-9]/g, "")}`; } return contractFn;