falcon
falcon copied to clipboard
`parse_query_string()`: change default value of `csv` to False
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
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.