diff --git a/CHANGELOG.md b/CHANGELOG.md index 5356597c..f12d0801 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,7 +36,8 @@ Using the following categories, list your changes in this order: ### Fixed -- Fix Django "StreamingHttpResponse must consume synchronous iterators" warning +- Fix Django `StreamingHttpResponse must consume synchronous iterators` warning +- Fix Django bug where file paths could fail to be followed on Windows ([Upstream PR](https://github.com/evansd/whitenoise/pull/474)) ## [1.0.0] - 2024-05-08 diff --git a/src/servestatic/middleware.py b/src/servestatic/middleware.py index f693106a..b269c0ee 100644 --- a/src/servestatic/middleware.py +++ b/src/servestatic/middleware.py @@ -4,9 +4,10 @@ import concurrent.futures import contextlib import os -from posixpath import basename +from posixpath import basename, normpath from typing import AsyncIterable from urllib.parse import urlparse +from urllib.request import url2pathname import django from aiofiles.base import AiofilesContextManager @@ -252,7 +253,10 @@ def add_files_from_finders(self): def candidate_paths_for_url(self, url): if self.use_finders and url.startswith(self.static_prefix): - path = finders.find(url[len(self.static_prefix) :]) + relative_url = url[len(self.static_prefix) :] + path = url2pathname(relative_url) + normalized_path = normpath(path).lstrip("/") + path = finders.find(normalized_path) if path: yield path paths = super().candidate_paths_for_url(url)