Skip to content

Commit d08087a

Browse files
authored
Merge pull request #110 from topcoder-platform/issues-652
Issues-652: fixed ChallengeID in Vanilla Dispatcher
2 parents e2b94b5 + cddd782 commit d08087a

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

Topcoder/class.topcoder.plugin.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ function gdn_dispatcher_beforeControllerMethod_handler($sender, $args){
897897
}
898898
} else if($args['Controller'] instanceof GroupController) {
899899
if (array_key_exists('groupid', $methodArgs)) {
900-
$groupID = (int) $methodArgs['groupid'];
900+
$groupID = self::convertToGroupID($methodArgs['groupid']);
901901
}
902902
} else if($args['Controller'] instanceof PostController) {
903903
if (array_key_exists('discussionid', $methodArgs)) {
@@ -943,6 +943,29 @@ function gdn_dispatcher_beforeControllerMethod_handler($sender, $args){
943943
}
944944
}
945945

946+
private static function convertToGroupID($id) {
947+
if(is_numeric($id) && $id > 0) {
948+
return $id;
949+
}
950+
951+
if(self::isValidUuid($id) === true) {
952+
$categoryModel = new CategoryModel();
953+
$category = $categoryModel->getByCode($id);
954+
return val('GroupID', $category, 0);
955+
}
956+
957+
return 0;
958+
}
959+
960+
private static function isValidUuid($uuid) {
961+
if(!is_string($uuid)) {
962+
return false;
963+
}
964+
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)) {
965+
return false;
966+
}
967+
return true;
968+
}
946969

947970
public function base_beforeBuildBreadcrumbs_handler($sender, $args) {
948971
if(Gdn::session()->isValid()) {

0 commit comments

Comments
 (0)