From cb2df59b45d4cb35790472f76b06c59b22c6213b Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Tue, 10 Feb 2015 23:32:23 +0100 Subject: api: Require the version to start with v Makes the URL easier to understand (especially the v1 case). Signed-off-by: Florian Pritz --- application/controllers/api.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'application/controllers/api.php') diff --git a/application/controllers/api.php b/application/controllers/api.php index 3297f0614..837f62e89 100644 --- a/application/controllers/api.php +++ b/application/controllers/api.php @@ -22,6 +22,13 @@ class Api extends MY_Controller { $requested_version = $this->uri->segment(2); $controller = $this->uri->segment(3); $function = $this->uri->segment(4); + + if (!preg_match("/^v([0-9]+)(.[0-9]+){0,2}$/", $requested_version)) { + throw new \exceptions\PublicApiException("api/invalid-version", "Invalid API version requested"); + } + + $requested_version = substr($requested_version, 1); + $major = intval(explode(".", $requested_version)[0]); if (!preg_match("/^[a-zA-Z-_]+$/", $controller)) { -- cgit v1.2.3-24-g4f1b