From c18bedeb811634248da313089ad674b82af92352 Mon Sep 17 00:00:00 2001 From: Seth Ladygo Date: Sat, 19 Oct 2019 22:09:10 -0700 Subject: [PATCH] markup utils: add clean_path() --- markup/utils.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/markup/utils.py b/markup/utils.py index 056a6f0..be8c883 100644 --- a/markup/utils.py +++ b/markup/utils.py @@ -1,4 +1,5 @@ import os +import re import shutil from django.conf import settings @@ -84,3 +85,10 @@ def ensure_dir(dir): def set_file_perms(file): os.chmod(file, 0o664) shutil.chown(file, group='procat') + + +def clean_path(path): + """Replace filesystem-hostile characters""" + path = re.sub(r'[<>]', '', path) + path = re.sub(r'[^\w@]', '_', path) + return path