diff --git a/index.php b/index.php index 3444c01..55bacf1 100644 --- a/index.php +++ b/index.php @@ -2,9 +2,9 @@ define('DEFAULT_TITLE', 'Mon panier bio'); -define('REQUEST_REGEX', '/\/(?[^\/]+)\/?(?[^\/]+)?\/?$/'); -define('SUPPLIER_REGEX', '/^[A-Za-z]\w{0,31}$/'); -define('EVENT_REGEX', '/^\d{4}\-[01]\d\-[0123]\d$/'); +define('SUPPLIER_REGEX', '[A-Za-z]\w{0,31}'); +define('EVENT_REGEX', '\d{4}\-[01]\d\-[0123]\d'); +define('REQUEST_REGEX', '/^https?:\/\/.+\/(?' . SUPPLIER_REGEX . ')\/?(?' . EVENT_REGEX . ')?\/?$/'); define('ACTION_REGEX', '/^[a-z]{1,16}$/i'); $baseUrl = trim((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], '/'); @@ -77,7 +77,7 @@ if (!isset($config)) $config = []; $action = (isset($_REQUEST['action']) and preg_match(ACTION_REGEX, $_REQUEST['action'])) ? $_REQUEST['action'] : null; $supplier = array_key_exists('supplier', $_REQUEST) ? $_REQUEST['supplier'] : $requestSupplier; -$hasSupplier = is_string($supplier) and preg_match(SUPPLIER_REGEX, $supplier); +$hasSupplier = is_string($supplier) and preg_match('/^' . SUPPLIER_REGEX . '$/', $supplier); $excludesFormatter = new \IntlDateFormatter('fr_FR.UTF8', \IntlDateFormatter::SHORT, \IntlDateFormatter::NONE, 'Europe/Paris'); @@ -195,7 +195,7 @@ try { $event = array_key_exists('event', $_REQUEST) ? $_REQUEST['event'] : $requestEvent; $hasEvent = ( is_string($event) - and preg_match(EVENT_REGEX, $event) + and preg_match('/^' . EVENT_REGEX . '$/', $event) and ((new \DateTimeImmutable($event)) instanceof \DateTimeImmutable) ); } catch (\Exception $exception) {