From 17d050507b9080581582f270c449715e48b63285 Mon Sep 17 00:00:00 2001 From: Olivier PEREZ Date: Sat, 5 Dec 2015 16:35:32 +0100 Subject: [PATCH] UrlNaming - Allow new id format when loading a poll --- app/classes/Framadate/Services/PollService.php | 4 ++-- app/inc/constants.php | 1 + studs.php | 4 +--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/classes/Framadate/Services/PollService.php b/app/classes/Framadate/Services/PollService.php index 2ccb9f8..2c4ed39 100644 --- a/app/classes/Framadate/Services/PollService.php +++ b/app/classes/Framadate/Services/PollService.php @@ -49,7 +49,7 @@ class PollService { * @return \stdClass|null The found poll, or null */ function findById($poll_id) { - if (preg_match('/^[\w\d]{16}$/i', $poll_id)) { + if (preg_match(POLL_REGEX, $poll_id)) { return $this->pollRepository->findById($poll_id); } @@ -57,7 +57,7 @@ class PollService { } public function findByAdminId($admin_poll_id) { - if (preg_match('/^[\w\d]{24}$/i', $admin_poll_id)) { + if (preg_match(ADMIN_POLL_REGEX, $admin_poll_id)) { return $this->pollRepository->findByAdminId($admin_poll_id); } diff --git a/app/inc/constants.php b/app/inc/constants.php index 2430cce..43a1fc4 100644 --- a/app/inc/constants.php +++ b/app/inc/constants.php @@ -22,6 +22,7 @@ const VERSION = '0.9'; // Regex const POLL_REGEX = '/^[a-z0-9-]*$/i'; +const ADMIN_POLL_REGEX = '/^[\w\d]{24}$/i'; const CHOICE_REGEX = '/^[012]$/'; const BOOLEAN_REGEX = '/^(on|off|true|false|1|0)$/i'; const BOOLEAN_TRUE_REGEX = '/^(on|true|1)$/i'; diff --git a/studs.php b/studs.php index 47a5626..67ff873 100644 --- a/studs.php +++ b/studs.php @@ -58,9 +58,7 @@ $securityService = new SecurityService(); if (!empty($_GET['poll'])) { $poll_id = filter_input(INPUT_GET, 'poll', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => POLL_REGEX]]); - if (strlen($poll_id) === 16) { - $poll = $pollService->findById($poll_id); - } + $poll = $pollService->findById($poll_id); } if (!$poll) {