From 970154cdebd99542c453e9ad104c8c0e6418becd Mon Sep 17 00:00:00 2001 From: Ferry Boender Date: Wed, 27 May 2015 22:14:36 +0200 Subject: [PATCH] Properly validate field uploads if the browser does not support HTML5 client side form validation. --- src/scriptform.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/scriptform.py b/src/scriptform.py index 05de06d..92b23ff 100755 --- a/src/scriptform.py +++ b/src/scriptform.py @@ -411,7 +411,7 @@ class FormDefinition: for field in self.fields: if 'required' in field and \ field['required'] is True and \ - field['name'] not in form_values: + (field['name'] not in form_values or form_values[field['name']] == ''): errors.setdefault(field['name'], []).append( "This field is required" ) @@ -943,8 +943,11 @@ class ScriptFormWebApp(WebAppHandler): tmp_files = [] for field_name in form_values: field = form_values[field_name] - if field.filename: - # Field is an uploaded file. Stream it to a temp file + if field.filename is not None: + # Field is an uploaded file. Stream it to a temp file if + # something was actually uploaded + if field.filename == '': + continue tmpfile = tempfile.mktemp(prefix="scriptform_") f = file(tmpfile, 'w') while True: