From 2a177ebc9f2e51dead013ded95b835392a73e3b6 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 2 Apr 2012 13:18:25 -0400 Subject: [PATCH] Use Django's slugify() to sanitize paths. --- chemdb/util.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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) -- 2.26.2