diff --git a/lib/utils/validation-utils.js b/lib/utils/validation-utils.js --- a/lib/utils/validation-utils.js +++ b/lib/utils/validation-utils.js @@ -108,6 +108,8 @@ const ashoatKeyserverID = '256'; +// Should be in sync with native/cpp/CommonCpp/NativeModules/\ +// PersistentStorageUtilities/ThreadOperationsUtilities/ThreadTypeEnum.h const uuidRegex = '[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}'; const idSchemaRegex = `(?:(?:[0-9]+|${uuidRegex})\\|)?(?:[0-9]+|${uuidRegex})`; diff --git a/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/ThreadOperationsUtilities/ThreadTypeEnum.h b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/ThreadOperationsUtilities/ThreadTypeEnum.h --- a/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/ThreadOperationsUtilities/ThreadTypeEnum.h +++ b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/ThreadOperationsUtilities/ThreadTypeEnum.h @@ -1,5 +1,7 @@ #pragma once +#import +#import #import namespace comm { @@ -28,4 +30,27 @@ ThreadType::PRIVATE, ThreadType::THICK_SIDEBAR}; +// Regex patterns - should be in sync with lib/utils/validation-utils.js +const std::string UUID_REGEX_STRING = + "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{" + "12}"; +const std::string ID_SCHEMA_REGEX_STRING = "(?:(?:[0-9]+|" + UUID_REGEX_STRING + + ")\\|)?(?:[0-9]+|" + UUID_REGEX_STRING + ")"; + +const std::regex IS_SCHEMA_REGEX("^" + ID_SCHEMA_REGEX_STRING + "$"); +const std::regex THICK_ID_REGEX("^" + UUID_REGEX_STRING + "$"); + +// Helper functions for regex testing +inline bool isSchemaID(const std::string &threadID) { + return std::regex_match(threadID, IS_SCHEMA_REGEX); +} + +inline bool isThickID(const std::string &threadID) { + return std::regex_match(threadID, THICK_ID_REGEX); +} + +inline bool threadIDMatchesKeyserverProtocol(const std::string &threadID) { + return isSchemaID(threadID) && !isThickID(threadID); +} + } // namespace comm diff --git a/web/shared-worker/_generated/comm_query_executor.wasm b/web/shared-worker/_generated/comm_query_executor.wasm index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@