summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorKaren Tracey <kmtracey@gmail.com>2009-04-04 17:42:43 +0000
committerKaren Tracey <kmtracey@gmail.com>2009-04-04 17:42:43 +0000
commit055f9a0ebf50ecc02e540304f81cc2e2d95613e3 (patch)
treee6ef2e64a9d2c50f43694486a7a8f7477e750418 /django
parent3c5f7bc262050bba42b998b50d9f5082bf981665 (diff)
[1.0.X] Fixed #10254: Changed the regex in get_valid_filename to allow unicode alphanumerics (thanks gulliver). Also updated the file_uploads test for this case to check the name after saving the uploaded file. As it was the test ensured that files with unicode characters in their names could be uploaded, but it wasn't actually ensuring that the unicode characters were preserved through save.
Backport of [10388] git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10389 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/utils/text.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/django/utils/text.py b/django/utils/text.py
index 1548cfa77e..cd631983d7 100644
--- a/django/utils/text.py
+++ b/django/utils/text.py
@@ -116,13 +116,13 @@ def get_valid_filename(s):
"""
Returns the given string converted to a string that can be used for a clean
filename. Specifically, leading and trailing spaces are removed; other
- spaces are converted to underscores; and all non-filename-safe characters
- are removed.
+ spaces are converted to underscores; and anything that is not a unicode
+ alphanumeric, dash, underscore, or dot, is removed.
>>> get_valid_filename("john's portrait in 2004.jpg")
u'johns_portrait_in_2004.jpg'
"""
s = force_unicode(s).strip().replace(' ', '_')
- return re.sub(r'[^-A-Za-z0-9_.]', '', s)
+ return re.sub(r'(?u)[^-\w.]', '', s)
get_valid_filename = allow_lazy(get_valid_filename, unicode)
def get_text_list(list_, last_word=ugettext_lazy(u'or')):