Skip to content
Myr

fix 'static_url_path' defaulting for empty paths

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

-prefix a path delimiter iff there's a path to delimit -ensures a valid default static route rule is created on application intialisation for the case 'static_folder=""' and implicit 'static_url_path'

authored by Pete Beardmore · committed by David Lord · parent b837606 · Browse files · 2 files+16 added−1 removed
This commit

State

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

Diff stats

2 files+16 added−1 removed

  • tests:+14 added−0 removed
  • other:+2 added−1 removed

2 files+16 added−1 removed

modified:flask/helpers.py+2 added-1 removed
968 unmodified lines
969 if self._static_url_path is not None:970 return self._static_url_path971972 if self.static_folder is not None:973 return "/" + os.path.basename(self.static_folder)973 basename = os.path.basename(self.static_folder)974 return "/" + basename if basename else ""975976 def _set_static_url_path(self, value):977 self._static_url_path = value978
135 unmodified lines
modified:tests/test_basic.py+14 added
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):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):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()144214431444def test_static_route_with_host_matching():1445 app = flask.Flask(__name__, host_matching=True, static_host="example.com")1446 c = app.test_client()1447 rv = c.get("http://example.com/static/index.html")
542 unmodified lines