﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
34341	FileSystemFinder harsh regarding its input on Windows	Marc Perrin	nobody	"It seems to me that `FileSystemFinder.find_location` code is unnecessarily harsh re `os.sep`.

(context: I got an issue about finding (React) static files **on Windows** with `whitenoise` lib > `django`)

See this code [https://github.com/django/django/blob/main/django/contrib/staticfiles/finders.py#L137]

i.e.

{{{
def find_location(self, root, path, prefix=None):
    """"""
    Find a requested static file in a location and return the found
    absolute path (or ``None`` if no match).
    """"""
    if prefix:
        prefix = '%s%s' % (prefix, os.sep)
        if not path.startswith(prefix):
            return None
        path = path[len(prefix):]
    path = safe_join(root, path)
    if os.path.exists(path):
        return path
}}}

In my case, when debugging I go into the `return None` ''a lot'' because `os.sep` is backslash, and the args of `find_location` are for example:

{{{
root = r'C:\some\folder\for\react\files'
path = 'bundled_react/some_file.hot-update.js'
prefix = 'bundled_react'
}}}

Right now, this basically forces to call `finders.find` with os-adapted paths (using e.g. `url2pathname`), but that seems unnecessarily harsh, considering that:
- other finders (e.g. `AppDirectoriesFinder`) seem much more lenient
- even within `FileSystemFinder.find_location`, that does not seem justified, as the `safe_join` called below is perfectly capable to do for example:
{{{
assert safe_join(r'C:\some\folder\for\react\files', 'some/path/for/a/file.js') == r'C:\some\folder\for\react\files\some\path\for\a\file.js'
}}}

NB: an old, related issue might be: [https://code.djangoproject.com/ticket/19046]

Also see [https://github.com/evansd/whitenoise/issues/472] - at first I thought it called for a change on `whitenoise` side, but now I'm thinking it would make sense on `django` side."	Bug	closed	contrib.staticfiles	3.2	Normal	invalid	Windows		Unreviewed	0	0	0	0	0	0
