From d4076cf07c70d7fccf82aba5c5acae3f3fb99447 Mon Sep 17 00:00:00 2001 From: frostming Date: Thu, 26 Dec 2019 09:33:42 +0800 Subject: [PATCH] strip the ending slash for static_url_path --- CHANGES.rst | 2 ++ src/flask/helpers.py | 2 +- tests/test_basic.py | 11 +++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index f684126a..ae07651a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -7,6 +7,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 3f401a5b..b730ca3e 100644 --- a/src/flask/helpers.py +++ b/src/flask/helpers.py @@ -1013,7 +1013,7 @@ class _PackageBoundObject(object): return self._static_url_path if self.static_folder is not None: - basename = os.path.basename(self.static_folder) + basename = os.path.basename(self.static_folder.rstrip("/")) return ("/" + basename).rstrip("/") @static_url_path.setter diff --git a/tests/test_basic.py b/tests/test_basic.py index 8ebdaba4..4d3b7b08 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -1425,6 +1425,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()