From: W. Trevor King Date: Mon, 2 Apr 2012 17:18:25 +0000 (-0400) Subject: Use Django's slugify() to sanitize paths. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=2a177ebc9f2e51dead013ded95b835392a73e3b6;p=chemdb.git Use Django's slugify() to sanitize paths. --- diff --git a/chemdb/util.py b/chemdb/util.py index 7910dbf..2d9f10b 100644 --- a/chemdb/util.py +++ b/chemdb/util.py @@ -3,6 +3,8 @@ import os.path as _os_path import re as _re +from django.template.defaultfilters import slugify as _slugify + from . import LOG as _LOG @@ -63,9 +65,9 @@ def valid_CASno(cas_string): return False def sanitize_path(string): - for a,b in [(' ', '-'), ('..', '-')]: + for a,b in [('..', '-')]: string = string.replace(a, b) - return string + return _slugify(string) def chemical_upload_to(instance, filename, storage=None): basename,extension = _os_path.splitext(filename)