Skip to content

Commit 4aac2e0

Browse files
committed
Restore support for using pathlib.Path for static_folder.
* No longer causes AttributeError: 'PosixPath' object has no attribute 'rstrip'. * This was broken by e6178fe which was released in 1.1.2. * Add a regression test that now passes. * Only rstrip os.path.sep from the static_folder value, rather than always rstripping both / and \ regardless of os. See #3557.
1 parent 93dd170 commit 4aac2e0

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

CHANGES.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
.. currentmodule:: flask
22

3+
Version 1.1.x
4+
-------------
5+
6+
Not yet released.
7+
8+
- Officially support passing a :class:`pathlib.Path` for
9+
``static_folder`` which stopped working in 1.1.2.
10+
11+
312
Version 1.1.2
413
-------------
514

src/flask/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ def static_folder(self):
10011001
@static_folder.setter
10021002
def static_folder(self, value):
10031003
if value is not None:
1004-
value = value.rstrip("/\\")
1004+
value = fspath(value).rstrip(os.path.sep)
10051005
self._static_folder = value
10061006

10071007
@property

tests/test_basic.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,16 @@ def test_static_url_empty_path_default(app):
14251425
rv.close()
14261426

14271427

1428+
@pytest.mark.skipif(sys.version_info < (3, 6), reason="requires Python >= 3.6")
1429+
def test_static_folder_with_pathlib_path(app):
1430+
from pathlib import Path
1431+
1432+
app = flask.Flask(__name__, static_folder=Path("static"))
1433+
rv = app.test_client().open("/static/index.html", method="GET")
1434+
assert rv.status_code == 200
1435+
rv.close()
1436+
1437+
14281438
def test_static_folder_with_ending_slash():
14291439
app = flask.Flask(__name__, static_folder="static/")
14301440

0 commit comments

Comments
 (0)