From a846b7664eda3a4c51a452e00638cf7337dc2013 Mon Sep 17 00:00:00 2001 From: doubleO8 Date: Sat, 9 Sep 2017 11:35:27 +0200 Subject: [PATCH] move utilities library and actually use it --- plugin/controllers/file.py | 6 ++++-- plugin/controllers/rest_fs_access.py | 4 +--- plugin/{ => controllers}/utilities.py | 0 3 files changed, 5 insertions(+), 5 deletions(-) rename plugin/{ => controllers}/utilities.py (100%) diff --git a/plugin/controllers/file.py b/plugin/controllers/file.py index 8bd4a84df..1f24cc0ab 100644 --- a/plugin/controllers/file.py +++ b/plugin/controllers/file.py @@ -19,6 +19,8 @@ from Components.config import config from Tools.Directories import fileExists +from utilities import lenient_force_utf_8, sanitise_filename_slashes + def new_getRequestHostname(self): host = self.getHeader(b'host') @@ -38,8 +40,8 @@ def render(self, request): action = request.args["action"][0] if "file" in request.args: - filename = request.args["file"][0].decode('utf-8', 'ignore').encode('utf-8') - filename = re.sub("^/+", "/", os.path.realpath(filename)) + filename = lenient_force_utf_8(request.args["file"][0]) + filename = sanitise_filename_slashes(os.path.realpath(filename)) if not os.path.exists(filename): return "File '%s' not found" % (filename) diff --git a/plugin/controllers/rest_fs_access.py b/plugin/controllers/rest_fs_access.py index 35091d3d4..510575d1a 100644 --- a/plugin/controllers/rest_fs_access.py +++ b/plugin/controllers/rest_fs_access.py @@ -43,11 +43,9 @@ import twisted.web.static from twisted.web import http +from utilities import MANY_SLASHES_REGEX import file -MANY_SLASHES_PATTERN = r'[\/]+' -MANY_SLASHES_REGEX = re.compile(MANY_SLASHES_PATTERN) - #: default path from which files will be served DEFAULT_ROOT_PATH = os.path.abspath(os.path.dirname(__file__)) diff --git a/plugin/utilities.py b/plugin/controllers/utilities.py similarity index 100% rename from plugin/utilities.py rename to plugin/controllers/utilities.py