From accce789ba508b367f5b84e06090dd323967bb69 Mon Sep 17 00:00:00 2001 From: Ruud Date: Tue, 19 Nov 2013 09:16:47 +0100 Subject: [PATCH] Normalize path sp function --- couchpotato/core/helpers/encoding.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/couchpotato/core/helpers/encoding.py b/couchpotato/core/helpers/encoding.py index bfebcc1f..e88c6ca3 100644 --- a/couchpotato/core/helpers/encoding.py +++ b/couchpotato/core/helpers/encoding.py @@ -49,8 +49,17 @@ def ss(original, *args): return u_original.encode('UTF-8') def sp(path, *args): + # Standardise encoding, normalise case, path and strip trailing '/' or '\' - return os.path.normcase(os.path.normpath(ss(path, *args))).rstrip(os.path.sep) + if not path or len(path) == 0: + return path + + path = os.path.normcase(os.path.normpath(ss(path, *args))) + + if path != os.path.sep: + path = path.rstrip(os.path.sep) + + return path def ek(original, *args): if isinstance(original, (str, unicode)):