From 8e7475ccf6805131ea089bc8b88994e4a1013ac1 Mon Sep 17 00:00:00 2001 From: Nikita Koshelev Date: Sat, 18 Nov 2017 01:22:42 +0300 Subject: [PATCH 1/2] Added regex escaping for `Router.add()` version parameter --- sanic/router.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sanic/router.py b/sanic/router.py index b601622c..2ba3140c 100644 --- a/sanic/router.py +++ b/sanic/router.py @@ -119,10 +119,8 @@ class Router: :return: Nothing """ if version is not None: - if uri.startswith('/'): - uri = "/".join(["/v{}".format(str(version)), uri[1:]]) - else: - uri = "/".join(["/v{}".format(str(version)), uri]) + version = re.escape(str(version)) + uri = "/".join(["/v{}".format(version.strip('/')), uri.lstrip('/')]) # add regular version self._add(uri, methods, handler, host, name) From 76511d61e0b7b1d35d4f30056b52dfce9e4e463b Mon Sep 17 00:00:00 2001 From: Nikita Koshelev Date: Sat, 18 Nov 2017 01:39:00 +0300 Subject: [PATCH 2/2] Added removing duplicate 'v' for `Router.add()` version parameter Fix sanic/router.py:123:80: E501 line too long (80 > 79 characters) --- sanic/router.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sanic/router.py b/sanic/router.py index 2ba3140c..208e3772 100644 --- a/sanic/router.py +++ b/sanic/router.py @@ -119,8 +119,8 @@ class Router: :return: Nothing """ if version is not None: - version = re.escape(str(version)) - uri = "/".join(["/v{}".format(version.strip('/')), uri.lstrip('/')]) + version = re.escape(str(version).strip('/').lstrip('v')) + uri = "/".join(["/v{}".format(version), uri.lstrip('/')]) # add regular version self._add(uri, methods, handler, host, name)