Commit cb9f797c authored by Phil Schleihauf's avatar Phil Schleihauf

Ignore case for allowed extensions

Fixes error where 'image.JPG' will be disallowed when `form.upload.FileUploadField.allowed_extensions` is set to `('jpg',)`, for example.
parent 96f5375c
...@@ -177,7 +177,8 @@ class FileUploadField(fields.TextField): ...@@ -177,7 +177,8 @@ class FileUploadField(fields.TextField):
return True return True
return ('.' in filename and return ('.' in filename and
filename.rsplit('.', 1)[1] in self.allowed_extensions) filename.rsplit('.', 1)[1].lower() in
map(str.lower, self.allowed_extensions))
def pre_validate(self, form): def pre_validate(self, form):
if (self.data and if (self.data and
......
...@@ -219,6 +219,12 @@ def test_image_upload_field(): ...@@ -219,6 +219,12 @@ def test_image_upload_field():
my_form.populate_obj(dummy) my_form.populate_obj(dummy)
eq_(dummy.upload, my_form.upload.data.filename) eq_(dummy.upload, my_form.upload.data.filename)
# check case-sensitivity for extensions
filename = op.join(op.dirname(__file__), 'data', 'copyleft.jpg')
with open(filename, 'rb') as fp:
with app.test_request_context(method='POST', data={'upload': (fp, 'copyleft.JPG')}):
my_form = TestNoResizeForm(helpers.get_form_data())
ok_(my_form.validate())
def test_relative_path(): def test_relative_path():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment