From cddd78235ed59fadda192008b8390969278c809f Mon Sep 17 00:00:00 2001 From: Bogdanova Olga Date: Tue, 18 Jan 2022 14:00:23 +0300 Subject: [PATCH] Issues-652: fixed ChallengeID in Vanilla Dispatcher --- Topcoder/class.topcoder.plugin.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Topcoder/class.topcoder.plugin.php b/Topcoder/class.topcoder.plugin.php index 8bc8a60..fdb1542 100644 --- a/Topcoder/class.topcoder.plugin.php +++ b/Topcoder/class.topcoder.plugin.php @@ -897,7 +897,7 @@ function gdn_dispatcher_beforeControllerMethod_handler($sender, $args){ } } else if($args['Controller'] instanceof GroupController) { if (array_key_exists('groupid', $methodArgs)) { - $groupID = (int) $methodArgs['groupid']; + $groupID = self::convertToGroupID($methodArgs['groupid']); } } else if($args['Controller'] instanceof PostController) { if (array_key_exists('discussionid', $methodArgs)) { @@ -943,6 +943,29 @@ function gdn_dispatcher_beforeControllerMethod_handler($sender, $args){ } } + private static function convertToGroupID($id) { + if(is_numeric($id) && $id > 0) { + return $id; + } + + if(self::isValidUuid($id) === true) { + $categoryModel = new CategoryModel(); + $category = $categoryModel->getByCode($id); + return val('GroupID', $category, 0); + } + + return 0; + } + + private static function isValidUuid($uuid) { + if(!is_string($uuid)) { + return false; + } + if (!\preg_match('/^[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}$/', $uuid)) { + return false; + } + return true; + } public function base_beforeBuildBreadcrumbs_handler($sender, $args) { if(Gdn::session()->isValid()) {