Skip to content

Commit

Permalink
Fix uri parsing for query parameter with empty brackets (#1501)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbeSneyders authored Apr 4, 2022
1 parent f236c68 commit 0b509f2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
18 changes: 11 additions & 7 deletions connexion/decorators/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ def snake_and_shadow(name):
return snake


def sanitized(name):
return name and re.sub('^[^a-zA-Z_]+', '',
re.sub('[^0-9a-zA-Z_]', '',
re.sub(r'\[(?!])', '_', name)))


def pythonic(name):
name = name and snake_and_shadow(name)
return sanitized(name)


def parameter_to_arg(operation, function, pythonic_params=False,
pass_context_arg_name=None):
"""
Expand All @@ -65,13 +76,6 @@ def parameter_to_arg(operation, function, pythonic_params=False,
"""
consumes = operation.consumes

def sanitized(name):
return name and re.sub('^[^a-zA-Z_]+', '', re.sub('[^0-9a-zA-Z[_]', '', re.sub(r'[\[]', '_', name)))

def pythonic(name):
name = name and snake_and_shadow(name)
return sanitized(name)

sanitize = pythonic if pythonic_params else sanitized
arguments, has_kwargs = inspect_function_arguments(function)

Expand Down
7 changes: 6 additions & 1 deletion tests/decorators/test_parameter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from unittest.mock import MagicMock

from connexion.decorators.parameter import parameter_to_arg
from connexion.decorators.parameter import parameter_to_arg, pythonic


def test_injection():
Expand All @@ -25,3 +25,8 @@ def get_arguments(self, *args, **kwargs):

parameter_to_arg(Op(), handler, pass_context_arg_name='framework_request_ctx')(request)
func.assert_called_with(p1='123', framework_request_ctx=request.context)


def test_pythonic_params():
assert pythonic('orderBy[eq]') == 'order_by_eq'
assert pythonic('ids[]') == 'ids'

0 comments on commit 0b509f2

Please sign in to comment.