From a12bf290da4e5ccc9cc7bd00a8e1ba8bccb50586 Mon Sep 17 00:00:00 2001 From: Pete Beardmore Date: Mon, 18 Mar 2019 18:50:08 +0000 Subject: [PATCH] fix 'static_url_path' defaulting for empty paths -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' --- flask/helpers.py | 3 ++- tests/test_basic.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/flask/helpers.py b/flask/helpers.py index 33e87b70..9825202a 100644 --- a/flask/helpers.py +++ b/flask/helpers.py @@ -970,7 +970,8 @@ class _PackageBoundObject(object): return self._static_url_path if self.static_folder is not None: - return "/" + os.path.basename(self.static_folder) + basename = os.path.basename(self.static_folder) + return "/" + basename if basename else "" def _set_static_url_path(self, value): self._static_url_path = value diff --git a/tests/test_basic.py b/tests/test_basic.py index 7a16ebd4..025b5a99 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -1427,6 +1427,20 @@ def test_static_url_path_with_ending_slash(): assert flask.url_for("static", filename="index.html") == "/foo/index.html" +def test_static_url_null_path(app): + app = flask.Flask(__name__, static_folder='', static_url_path='') + rv = app.test_client().open('/static/index.html', method='GET') + assert rv.status_code == 200 + rv.close() + + +def test_static_url_null_path_defaulting(app): + app = flask.Flask(__name__, static_folder='') + rv = app.test_client().open('/static/index.html', method='GET') + assert rv.status_code == 200 + rv.close() + + def test_static_route_with_host_matching(): app = flask.Flask(__name__, host_matching=True, static_host="example.com") c = app.test_client()