From 22b661ac491683ff0e1225242528291ca2f38fd8 Mon Sep 17 00:00:00 2001 From: Dev Date: Mon, 23 Sep 2024 14:33:47 +0100 Subject: [PATCH] Moved mongo id validation into its own function --- project/src/helpers/InventoryHelper.ts | 2 +- project/src/utils/HashUtil.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/project/src/helpers/InventoryHelper.ts b/project/src/helpers/InventoryHelper.ts index 985f96a7..bd8c62e9 100644 --- a/project/src/helpers/InventoryHelper.ts +++ b/project/src/helpers/InventoryHelper.ts @@ -1141,7 +1141,7 @@ export class InventoryHelper { public validateInventoryUsesMonogoIds(itemsToValidate: Item[]) { for (const item of itemsToValidate) { - if (!/^[a-fA-F0-9]{24}$/.test(item._id)) { + if (!this.hashUtil.isValidMongoId(item._id)) { throw new Error( `This profile is not compatible with 3.10.0, It contains an item with the ID: ${item._id} that is not compatible. Loading of SPT has been halted, use another profile or create a new one.`, ); diff --git a/project/src/utils/HashUtil.ts b/project/src/utils/HashUtil.ts index 174f819d..0553ad30 100644 --- a/project/src/utils/HashUtil.ts +++ b/project/src/utils/HashUtil.ts @@ -17,6 +17,15 @@ export class HashUtil { return mongoid(); } + /** + * is the passed in string a valid mongo id + * @param stringToCheck String to check + * @returns True when string is a valid mongo id + */ + public isValidMongoId(stringToCheck: string) { + return /^[a-fA-F0-9]{24}$/.test(stringToCheck); + } + public generateMd5ForData(data: string): string { return this.generateHashForData("md5", data); }