diff --git a/CHANGES.rst b/CHANGES.rst index a9c22511..394cc842 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -36,6 +36,8 @@ Unreleased - The ``flask`` command entry point is simplified to take advantage of Werkzeug 0.15's better reloader support. This bumps the Werkzeug dependency to >= 0.15. :issue:`3022` +- Support ``static_url_path`` that ends with a forward slash. + :issue:`3134` .. _#2935: https://github.com/pallets/flask/issues/2935 .. _#2957: https://github.com/pallets/flask/issues/2957 diff --git a/flask/app.py b/flask/app.py index 2fbb5e3f..8424ce98 100644 --- a/flask/app.py +++ b/flask/app.py @@ -587,7 +587,7 @@ class Flask(_PackageBoundObject): bool(static_host) == host_matching ), "Invalid static_host/host_matching combination" self.add_url_rule( - self.static_url_path + "/", + self.static_url_path.rstrip("/") + "/", endpoint="static", host=static_host, view_func=self.send_static_file, diff --git a/flask/blueprints.py b/flask/blueprints.py index dc193a8d..aea8ecec 100644 --- a/flask/blueprints.py +++ b/flask/blueprints.py @@ -198,7 +198,7 @@ class Blueprint(_PackageBoundObject): if self.has_static_folder: state.add_url_rule( - self.static_url_path + "/", + self.static_url_path.rstrip("/") + "/", view_func=self.send_static_file, endpoint="static", ) diff --git a/tests/test_basic.py b/tests/test_basic.py index 3158ee09..1f41920e 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -1399,6 +1399,17 @@ def test_static_url_path(): assert flask.url_for("static", filename="index.html") == "/foo/index.html" +def test_static_url_path_with_ending_slash(): + app = flask.Flask(__name__, static_url_path="/foo/") + app.testing = True + rv = app.test_client().get("/foo/index.html") + assert rv.status_code == 200 + rv.close() + + with app.test_request_context(): + assert flask.url_for("static", filename="index.html") == "/foo/index.html" + + def test_static_route_with_host_matching(): app = flask.Flask(__name__, host_matching=True, static_host="example.com") c = app.test_client()