Opened 5 years ago
Closed 5 years ago
#30912 closed Uncategorized (wontfix)
django.utils._os.safe_join breaks on Windows for paths that end in a slash/backslash
Reported by: | gcbirzan | Owned by: | nobody |
---|---|---|---|
Component: | Utilities | Version: | 3.0 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
On Linux:
os.path.abspath('/foo/bar/') '/foo/bar'
On Windows:
os.path.abspath(r'c:/foo/bar/') 'c:\\foo\\bar\\'
At the beginning of the function, abspath is called on the base_path. This removes the trailing slash on Linux, but not on Windows. Further down, in order to compare whether the normalised path is under base_path, this happens:
normcase(final_path).startswith(normcase(base_path + sep))
On Windows, since base_path now has a trailing backslash, this will always fail.
There are two solutions I see here. The first is to use the fallback from ntpath, which is the same implementation as the one from posixpath.
os.path._abspath_fallback('c:/foo/bar/') 'c:\\foo\\bar'
The second is to just strip the trailing slash, as it'll be added anyway when needed. I'm, personally, leaning towards the first option...
Change History (2)
comment:1 by , 5 years ago
comment:2 by , 5 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Ah. Actually, this only happens on Python 3.7.1. Hum. I'll just close it, I guess, since upgrading python will fix it.