Skip to content
Myr

strip static url trailing slash at assignment

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Lord · committed by David Lord · parent a12bf29 · Browse files · 5 files+21 added−19 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+21 added−19 removed

  • tests:+2 added−2 removed
  • other:+19 added−17 removed

5 files+21 added−19 removed

modified:flask/app.py+3 added-6 removed
406 unmodified lines
407 _PackageBoundObject.__init__(408 self, import_name, template_folder=template_folder, root_path=root_path409 )410411 if static_url_path is not None:412 self.static_url_path = static_url_path411 self.static_url_path = static_url_path412 self.static_folder = static_folder413414 if static_folder is not None:415 self.static_folder = static_folder416414 if instance_path is None:415 instance_path = self.auto_find_instance_path()416 elif not os.path.isabs(instance_path):417 raise ValueError(
172 unmodified lines
590 assert (591 bool(static_host) == host_matching592 ), "Invalid static_host/host_matching combination"593 self.add_url_rule(597 self.static_url_path.rstrip("/") + "/<path:filename>",594 self.static_url_path + "/<path:filename>",595 endpoint="static",596 host=static_host,597 view_func=self.send_static_file,598 )
1815 unmodified lines
modified:flask/blueprints.py+1 added-1 removed
206 unmodified lines
207 state = self.make_setup_state(app, options, first_registration)208209 if self.has_static_folder:210 state.add_url_rule(211 self.static_url_path.rstrip("/") + "/<path:filename>",211 self.static_url_path + "/<path:filename>",212 view_func=self.send_static_file,213 endpoint="static",214 )215
312 unmodified lines
modified:flask/helpers.py+13 added-10 removed
963 unmodified lines
964 doc="The absolute path to the configured static folder.",965 )966 del _get_static_folder, _set_static_folder967968 @property968 def _get_static_url_path(self):969 def static_url_path(self):970 """The URL prefix that the static route will be accessible from.971972 If it was not configured during init, it is derived from973 :attr:`static_folder`.974 """975 if self._static_url_path is not None:976 return self._static_url_path977978 if self.static_folder is not None:979 basename = os.path.basename(self.static_folder)974 return "/" + basename if basename else ""980 return ("/" + basename).rstrip("/")981982 @static_url_path.setter976 def _set_static_url_path(self, value):983 def static_url_path(self, value):984 if value is not None:985 value = value.rstrip("/")986987 self._static_url_path = value988979 static_url_path = property(980 _get_static_url_path,981 _set_static_url_path,982 doc="The URL prefix that the static route will be registered for.",983 )984 del _get_static_url_path, _set_static_url_path985989 @property990 def has_static_folder(self):991 """This is ``True`` if the package bound object's container has a992 folder for static files.
124 unmodified lines
modified:tests/test_basic.py+2 added-2 removed
1425 unmodified lines
1426 with app.test_request_context():1427 assert flask.url_for("static", filename="index.html") == "/foo/index.html"142814291430def test_static_url_null_path(app):1430def test_static_url_empty_path(app):1431 app = flask.Flask(__name__, static_folder='', static_url_path='')1432 rv = app.test_client().open('/static/index.html', method='GET')1433 assert rv.status_code == 2001434 rv.close()143514361437def test_static_url_null_path_defaulting(app):1437def test_static_url_empty_path_default(app):1438 app = flask.Flask(__name__, static_folder='')1439 rv = app.test_client().open('/static/index.html', method='GET')1440 assert rv.status_code == 2001441 rv.close()
548 unmodified lines
modified:CHANGES.rst+2 added
36 unmodified lines
37 of Werkzeug 0.15's better reloader support. This bumps the Werkzeug38 dependency to >= 0.15. :issue:`3022`39- Support ``static_url_path`` that ends with a forward slash.40 :issue:`3134`41- Support empty ``static_folder`` without requiring setting an empty42 ``static_url_path`` as well. :pr:`3124`43- :meth:`jsonify` supports :class:`dataclasses.dataclass` objects.44 :pr:`3195`45- Allow customizing the :attr:`Flask.url_map_class` used for routing.46 :pr:`3069`
968 unmodified lines