strip static url trailing slash at assignment

This commit is contained in:
David Lord 2019-05-25 11:14:49 -07:00
parent a12bf290da
commit ed9ab2d3b6
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
5 changed files with 21 additions and 19 deletions

View file

@ -408,11 +408,8 @@ class Flask(_PackageBoundObject):
self, import_name, template_folder=template_folder, root_path=root_path
)
if static_url_path is not None:
self.static_url_path = static_url_path
if static_folder is not None:
self.static_folder = static_folder
self.static_url_path = static_url_path
self.static_folder = static_folder
if instance_path is None:
instance_path = self.auto_find_instance_path()
@ -594,7 +591,7 @@ class Flask(_PackageBoundObject):
bool(static_host) == host_matching
), "Invalid static_host/host_matching combination"
self.add_url_rule(
self.static_url_path.rstrip("/") + "/<path:filename>",
self.static_url_path + "/<path:filename>",
endpoint="static",
host=static_host,
view_func=self.send_static_file,

View file

@ -208,7 +208,7 @@ class Blueprint(_PackageBoundObject):
if self.has_static_folder:
state.add_url_rule(
self.static_url_path.rstrip("/") + "/<path:filename>",
self.static_url_path + "/<path:filename>",
view_func=self.send_static_file,
endpoint="static",
)

View file

@ -965,24 +965,27 @@ class _PackageBoundObject(object):
)
del _get_static_folder, _set_static_folder
def _get_static_url_path(self):
@property
def static_url_path(self):
"""The URL prefix that the static route will be accessible from.
If it was not configured during init, it is derived from
:attr:`static_folder`.
"""
if self._static_url_path is not None:
return self._static_url_path
if self.static_folder is not None:
basename = os.path.basename(self.static_folder)
return "/" + basename if basename else ""
return ("/" + basename).rstrip("/")
@static_url_path.setter
def static_url_path(self, value):
if value is not None:
value = value.rstrip("/")
def _set_static_url_path(self, value):
self._static_url_path = value
static_url_path = property(
_get_static_url_path,
_set_static_url_path,
doc="The URL prefix that the static route will be registered for.",
)
del _get_static_url_path, _set_static_url_path
@property
def has_static_folder(self):
"""This is ``True`` if the package bound object's container has a