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

Blueprint view function name should not contain dots #2450

Merged
merged 1 commit into from
Oct 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ Major release, unreleased
``app.debug`` each time. Only one format is used, not different ones
depending on ``app.debug``. No handlers are removed, and a handler is only
added if no handlers are already configured. (`#2436`_)
- Blueprint view function name may not contain dots. (`#2450`_)

.. _#1421: https://github.com/pallets/flask/issues/1421
.. _#1489: https://github.com/pallets/flask/pull/1489
Expand Down Expand Up @@ -144,6 +145,7 @@ Major release, unreleased
.. _#2416: https://github.com/pallets/flask/pull/2416
.. _#2430: https://github.com/pallets/flask/pull/2430
.. _#2436: https://github.com/pallets/flask/pull/2436
.. _#2450: https://github.com/pallets/flask/pull/2450

Version 0.12.2
--------------
Expand Down
2 changes: 2 additions & 0 deletions flask/blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ def add_url_rule(self, rule, endpoint=None, view_func=None, **options):
"""
if endpoint:
assert '.' not in endpoint, "Blueprint endpoints should not contain dots"
if view_func:
assert '.' not in view_func.__name__, "Blueprint view function name should not contain dots"

This comment was marked as off-topic.

self.record(lambda s:
s.add_url_rule(rule, endpoint, view_func, **options))

Expand Down
9 changes: 9 additions & 0 deletions tests/test_blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,15 @@ def foo_foo_foo():
lambda: None
)

foo_foo_foo.__name__ = 'bar.123'

pytest.raises(
AssertionError,
lambda: bp.add_url_rule(
'/bar/123', view_func=foo_foo_foo
)
)

app.register_blueprint(bp, url_prefix='/py')

assert client.get('/py/foo').data == b'bp.foo'
Expand Down