Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix uri parsing for query parameter with empty brackets #1501

Merged
merged 1 commit into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'