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); }