diff options
-rw-r--r-- | cherrypy/__init__.py | 6 | ||||
-rw-r--r-- | cherrypy/lib/cptools.py | 4 |
2 files changed, 5 insertions, 5 deletions
diff --git a/cherrypy/__init__.py b/cherrypy/__init__.py index 45906b53..bbc2e459 100644 --- a/cherrypy/__init__.py +++ b/cherrypy/__init__.py @@ -186,16 +186,16 @@ def url(path="", qs="", script_name=None, base=None, relative=False): qs = '?' + qs if request.app: - if path[:1] != "/": + if not path.startswith("/"): # Append/remove trailing slash from path_info as needed # (this is to support mistyped URL's without redirecting; # if you want to redirect, use tools.trailing_slash). pi = request.path_info if request.is_index is True: - if pi[-1:] != '/': + if not pi.endswith('/'): pi = pi + '/' elif request.is_index is False: - if pi[-1:] == '/' and pi != '/': + if pi.endswith('/') and pi != '/': pi = pi[:-1] if path == "": diff --git a/cherrypy/lib/cptools.py b/cherrypy/lib/cptools.py index 8eff36ef..5b80a1c3 100644 --- a/cherrypy/lib/cptools.py +++ b/cherrypy/lib/cptools.py @@ -309,13 +309,13 @@ def trailing_slash(missing=True, extra=False): if request.is_index is True: if missing: - if pi[-1:] != '/': + if not pi.endswith('/'): new_url = cherrypy.url(pi + '/', request.query_string) raise cherrypy.HTTPRedirect(new_url) elif request.is_index is False: if extra: # If pi == '/', don't redirect to ''! - if pi[-1:] == '/' and pi != '/': + if pi.endswith('/') and pi != '/': new_url = cherrypy.url(pi[:-1], request.query_string) raise cherrypy.HTTPRedirect(new_url) |