fix routing issue with slashes

This commit is contained in:
Raphael Deem
2017-02-27 19:54:58 -08:00
parent 13f81e9a6f
commit 21fb1dff7e
2 changed files with 22 additions and 4 deletions

View File

@@ -98,10 +98,15 @@ class Router:
def add(self, uri, methods, handler, host=None):
# add regular version
self._add(uri, methods, handler, host)
slash_is_missing = (not uri[-1].endswith('/')
and not self.routes_all.get(uri + '/', False))
without_slash_is_missing = (not self.routes_all.get(uri[:-1], False)
and uri is not '/')
slash_is_missing = (
not uri[-1] == '/'
and not self.routes_all.get(uri + '/', False)
)
without_slash_is_missing = (
uri[-1] == '/'
and not self.routes_all.get(uri[:-1], False)
and not uri == '/'
)
# add version with trailing slash
if slash_is_missing:
self._add(uri + '/', methods, handler, host)