UrlNaming - Allow new id format when loading a poll

This commit is contained in:
Olivier PEREZ 2015-12-05 16:35:32 +01:00
parent 1efd7b9ab0
commit 17d050507b
3 changed files with 4 additions and 5 deletions

View File

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

View File

@ -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';

View File

@ -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) {