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


On Linux:


On Windows:


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.


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 gcbirzan, 5 years ago

Ah. Actually, this only happens on Python 3.7.1. Hum. I'll just close it, I guess, since upgrading python will fix it.

comment:2 by gcbirzan, 5 years ago

Resolution: wontfix
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top