The Wayback Machine - https://web.archive.org/web/20190531024112/https://github.com/aws/chalice/issues/511
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

Mapped URI parameters should be implicitly decoded / unquoted #511

Open
jstell opened this issue Sep 1, 2017 · 4 comments

Comments

2 participants
@jstell
Copy link

commented Sep 1, 2017

Maybe I'm missing something, but shouldn't mapped parameter values be implicitly decoded?

CITIES_TO_STATE  = { 
    'seattle': 'WA',
    'portland': 'OR',
    'Los Angeles': 'CA' 
}
@app.route('/cities/{city}')
def state_of_city(city):
    return {'state': CITIES_TO_STATE[city]}

For example, if I'm looking for what state Los Angeles is in, I will do a GET /cities/Los%20Angeles. The above handler will not give me the expected answer, because it doesn't unquote Los%20Angeles back to Los Angeles.

Shouldn't there be a call to do city = urllib.unquote_plus(request.query_params['city']) ?

@jamesls

This comment has been minimized.

Copy link
Member

commented Sep 1, 2017

Yes, thanks for reporting. We'll get that updated.

@jstell

This comment has been minimized.

Copy link
Author

commented Sep 1, 2017

@jamesls Thanks for the quick response.
I was envisioning this as more than a documentation issue. Shouldn't the framework implicitly do the unquote? I'm new to Chalice (and, relatively, python), but I was looking at Chalice__call__ where it creates the function arguments:

function_args = {name: event['pathParameters'][name]
                         for name in route_entry.view_args}

and thinking it could be changed to something like this:

function_args = {name: urllib.unquote_plus(event['pathParameters'][name])
                         for name in route_entry.view_args}
@jamesls

This comment has been minimized.

Copy link
Member

commented Sep 5, 2017

The tricky part here is because we're past the 1.0 release we have to maintain backwards compatibility, given people already have to unquote these params themselves so if we start to do that for them we may break users.

I'd be interested in alternatives that could still preserve backwards compatibility.

@jstell

This comment has been minimized.

Copy link
Author

commented Sep 5, 2017

@jamesls I agree that it's best to preserve existing behavior (at least until the next major release).
Perhaps an "auto_unquote_path_parameters" configuration option, defaulted to false?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.