require a non-empty name for blueprints

This commit is contained in:
Evgeny Mozhaev 2023-03-04 21:09:34 +03:00 committed by David Lord
parent 7ee9ceb71e
commit b8b410014d
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
3 changed files with 10 additions and 0 deletions

View file

@ -35,6 +35,8 @@ Unreleased
- Ensure subdomains are applied with nested blueprints. :issue:`4834` - Ensure subdomains are applied with nested blueprints. :issue:`4834`
- ``config.from_file`` can use ``text=False`` to indicate that the parser wants a - ``config.from_file`` can use ``text=False`` to indicate that the parser wants a
binary file instead. :issue:`4989` binary file instead. :issue:`4989`
- If a blueprint is created with an empty name it raises a ``ValueError``.
:issue:`5010`
Version 2.2.4 Version 2.2.4

View file

@ -190,6 +190,9 @@ class Blueprint(Scaffold):
root_path=root_path, root_path=root_path,
) )
if not name:
raise ValueError("'name' may not be empty.")
if "." in name: if "." in name:
raise ValueError("'name' may not contain a dot '.' character.") raise ValueError("'name' may not contain a dot '.' character.")

View file

@ -256,6 +256,11 @@ def test_dotted_name_not_allowed(app, client):
flask.Blueprint("app.ui", __name__) flask.Blueprint("app.ui", __name__)
def test_empty_name_not_allowed(app, client):
with pytest.raises(ValueError):
flask.Blueprint("", __name__)
def test_dotted_names_from_app(app, client): def test_dotted_names_from_app(app, client):
test = flask.Blueprint("test", __name__) test = flask.Blueprint("test", __name__)