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

parse_query_string(): change default value of csv to False #1999

Closed
tahseenjamal opened this issue Jan 1, 2022 · 1 comment · Fixed by #2200
Closed

parse_query_string(): change default value of csv to False #1999

tahseenjamal opened this issue Jan 1, 2022 · 1 comment · Fixed by #2200

Comments

@tahseenjamal
Copy link

Some url encoders don't encode comma to %2C

And in such cases, the Falcon Query parser creates an array instead of a string.

If you have a query string "ABC,ABC" instead of "ABC%2CABC" then if you try to fetch if using

msg = falcon.uri.parse_query_string(req.query_string).get("message")

then msg would be an array instead of string

msg = ['ABC', 'ABC']

which is incorrect

@vytas7
Copy link
Member

vytas7 commented Jan 1, 2022

Hi @tahseenjamal!
The behaviour you observe is by design, see the csv parameter in parse_query_string() and the related explanatory notes.

However, we have changed the default behaviour of req.params not to split on comma, see also RequestOptions.auto_parse_qs_csv. As said, given that the default value is now not to automatically split, you could get rid of this side effect by simply changing to

msg = req.params.get("message")

Note that you still may get a list back in the case someone sends repeated params, e.g.,?message=one&message=another.
You can either add validation for this case, or just grab the first one via

msg = req.get_param("message")

Other than that, I agree that this discrepancy is a bit confusing. We should probably change the behaviour of parse_query_string() to match the new default of not splitting on comma.

@vytas7 vytas7 changed the title Query Parameter Decoding not correct uri.parse_query_string(): change default value of csv to False Jan 1, 2022
@vytas7 vytas7 changed the title uri.parse_query_string(): change default value of csv to False parse_query_string(): change default value of csv to False Jan 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants