From ed143fb73af3b510fcce80dca48e42d91652c528 Mon Sep 17 00:00:00 2001 From: Ferry Boender Date: Mon, 25 May 2015 12:22:10 +0200 Subject: [PATCH] Cast min/max/minlen/maxlen values to proper types. --- src/scriptform.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/scriptform.py b/src/scriptform.py index ea5c76d..a95e848 100755 --- a/src/scriptform.py +++ b/src/scriptform.py @@ -443,9 +443,9 @@ class FormDefinition: maxlen = field_def.get('maxlen', None) minlen = field_def.get('minlen', None) - if minlen is not None and len(value) < minlen: + if minlen is not None and len(value) < int(minlen): raise ValidationError("Minimum length is {0}".format(minlen)) - if maxlen is not None and len(value) > maxlen: + if maxlen is not None and len(value) > int(maxlen): raise ValidationError("Maximum length is {0}".format(maxlen)) return value @@ -460,9 +460,9 @@ class FormDefinition: except ValueError: raise ValidationError("Must be an integer number") - if min is not None and value < min: + if min is not None and value < int(min): raise ValidationError("Minimum value is {0}".format(min)) - if max is not None and value > max: + if max is not None and value > int(max): raise ValidationError("Maximum value is {0}".format(max)) return int(value) @@ -477,9 +477,9 @@ class FormDefinition: except ValueError: raise ValidationError("Must be an real (float) number") - if min is not None and value < min: + if min is not None and value < float(min): raise ValidationError("Minimum value is {0}".format(min)) - if max is not None and value > max: + if max is not None and value > float(max): raise ValidationError("Maximum value is {0}".format(max)) return float(value) @@ -529,12 +529,10 @@ class FormDefinition: minlen = field_def.get('minlen', None) maxlen = field_def.get('maxlen', None) - if minlen is not None: - if len(value) < minlen: + if minlen is not None and len(value) < int(minlen): raise ValidationError("minimum length is {0}".format(minlen)) - if maxlen is not None: - if len(value) > maxlen: + if maxlen is not None and len(value) > int(maxlen): raise ValidationError("maximum length is {0}".format(maxlen)) return value @@ -543,8 +541,7 @@ class FormDefinition: value = form_values[field_def['name']] minlen = field_def.get('minlen', None) - if minlen is not None: - if len(value) < minlen: + if minlen is not None and len(value) < int(minlen): raise ValidationError("minimum length is {0}".format(minlen)) return value