Skip to content

Commit

Permalink
Minor bug fixing for lists
Browse files Browse the repository at this point in the history
  • Loading branch information
Ge0rg3 committed Nov 24, 2023
1 parent d3603f1 commit 3bac6f0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion flask_parameter_validation/parameter_types/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def validate(self, value):
for value in values:
# Min length
if self.min_str_length is not None:
if len(value) < self.min_str_length:
if hasattr(value, "len") and len(value) < self.min_str_length:
raise ValueError(
f"must have at least {self.min_str_length} characters."
)
Expand Down
11 changes: 6 additions & 5 deletions flask_parameter_validation/parameter_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,12 @@ def validate(self, expected_input, all_request_inputs):
if str(exp_type).startswith("typing.List"):
if type(user_input) is list:
# Only convert if validation passes
if all(type(inp) in exp_type.__args__ for inp in user_input):
expected_input_type = exp_type
expected_input_types = expected_input_type.__args__
expected_input_type_str = str(exp_type)
user_inputs = user_input
if hasattr(exp_type, "__args__"):
if all(type(inp) in exp_type.__args__ for inp in user_input):
expected_input_type = exp_type
expected_input_types = expected_input_type.__args__
expected_input_type_str = str(exp_type)
user_inputs = user_input
# If list, expand inner typing items. Otherwise, convert to list to match anyway.
elif expected_input_type_str.startswith("typing.List"):
expected_input_types = expected_input_type.__args__
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

setup(
name='Flask-Parameter-Validation',
version='2.2.2',
version='2.2.3',
url='https://github.com/Ge0rg3/flask-parameter-validation',
license='MIT',
author='George Omnet',
Expand Down

0 comments on commit 3bac6f0

Please sign in to comment.