diff --git a/CHANGES.rst b/CHANGES.rst index 175f9e87..382653c6 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -27,6 +27,8 @@ Unreleased - Work around an issue when running the ``flask`` command with an external debugger on Windows. :issue:`3297` +- The static route will not catch all URLs if the ``Flask`` + ``static_folder`` argument ends with a slash. :issue:`3452` Version 1.1.1 diff --git a/src/flask/helpers.py b/src/flask/helpers.py index e3e59248..ef344d7a 100644 --- a/src/flask/helpers.py +++ b/src/flask/helpers.py @@ -1012,6 +1012,8 @@ class _PackageBoundObject(object): @static_folder.setter def static_folder(self, value): + if value is not None: + value = value.rstrip("/\\") self._static_folder = value @property diff --git a/tests/test_basic.py b/tests/test_basic.py index f2e3ca96..2328a82c 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -1426,6 +1426,17 @@ def test_static_url_empty_path_default(app): rv.close() +def test_static_folder_with_ending_slash(): + app = flask.Flask(__name__, static_folder="static/") + + @app.route("/") + def catch_all(path): + return path + + rv = app.test_client().get("/catch/all") + assert rv.data == b"catch/all" + + def test_static_route_with_host_matching(): app = flask.Flask(__name__, host_matching=True, static_host="example.com") c = app.test_client()