markup utils: add clean_path()

This commit is contained in:
2019-10-19 22:09:10 -07:00
parent e434d3f705
commit c18bedeb81

View File

@ -1,4 +1,5 @@
import os import os
import re
import shutil import shutil
from django.conf import settings from django.conf import settings
@ -84,3 +85,10 @@ def ensure_dir(dir):
def set_file_perms(file): def set_file_perms(file):
os.chmod(file, 0o664) os.chmod(file, 0o664)
shutil.chown(file, group='procat') 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