﻿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
30912	django.utils._os.safe_join breaks on Windows for paths that end in a slash/backslash	gcbirzan	nobody	"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..."	Uncategorized	closed	Utilities	3.0	Normal	wontfix			Unreviewed	0	0	0	0	0	0
