url_for appends ? if called with empty query argument #1992
Comments
|
The version with the question mark is valid. I can't remember the exact reason, but this has been discussed before. If you are in a situation where you'll be sending potentially empty arguments and don't want it, you can write a wrapper to strip it off. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Expected Behavior
If
url_foris called with a query argument that is an empty list (and no other query arguments), the URL should have no query part at all, including no trailing question mark. (When called with a nonempty list, it adds several query arguments with the same name, which is what I expect; when called withNone, it omits the question mark already.)Full example: https://github.com/lucaswerkmeister/repro-flask-url_for-empty
Actual Behavior
The URL has a question mark at the end (in the above example:
/?).Environment
Workaround
Replace the empty list with
Noneby appendingor Noneto the argument. (This also works in Jinja2 templates.)The text was updated successfully, but these errors were encountered: