From 3ae086aff4ac24792c026e49775dc8feca2aa4eb Mon Sep 17 00:00:00 2001 From: Bo Maryniuk Date: Wed, 23 Nov 2016 19:07:20 +0100 Subject: [PATCH] Add filename sanitiser --- salt/utils/general.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/salt/utils/general.py b/salt/utils/general.py index 413a5352b8..a73cda3f0f 100644 --- a/salt/utils/general.py +++ b/salt/utils/general.py @@ -35,6 +35,16 @@ class InputSanitizer(object): return text(value) + @staticmethod + def filename(value): + ''' + Remove everything that would affect paths in the filename + + :param value: + :return: + ''' + return re.sub('[^a-zA-Z0-9.-_ ]', '', os.path.basename(InputSanitizer.trim(value))) + clean = InputSanitizer()