Expected Behavior
If url_for is 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 with None, it omits the question mark already.)
@app.route('/')
def index():
return flask.url_for('index', extra_param=[])
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
- Python version: 3.9.1
- Flask version: 1.1.2
- Werkzeug version: 1.0.1
Workaround
Replace the empty list with None by appending or None to the argument. (This also works in Jinja2 templates.)
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.)