|
@@ -1,6 +1,6 @@
|
|
|
import os
|
|
|
import stat
|
|
|
-from os.path import join, normcase, normpath, abspath, isabs, sep
|
|
|
+from os.path import join, normcase, normpath, abspath, isabs, sep, dirname
|
|
|
from django.utils.encoding import force_text
|
|
|
from django.utils import six
|
|
|
|
|
@@ -41,13 +41,16 @@ def safe_join(base, *paths):
|
|
|
paths = [force_text(p) for p in paths]
|
|
|
final_path = abspathu(join(base, *paths))
|
|
|
base_path = abspathu(base)
|
|
|
- base_path_len = len(base_path)
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if not normcase(final_path).startswith(normcase(base_path)) \
|
|
|
- or final_path[base_path_len:base_path_len+1] not in ('', sep):
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (not normcase(final_path).startswith(normcase(base_path + sep)) and
|
|
|
+ normcase(final_path) != normcase(base_path) and
|
|
|
+ dirname(normcase(base_path)) != normcase(base_path)):
|
|
|
raise ValueError('The joined path (%s) is located outside of the base '
|
|
|
'path component (%s)' % (final_path, base_path))
|
|
|
return final_path
|