From f7a3bdc6db7aefeeb974c0b9800bbe64d152f842 Mon Sep 17 00:00:00 2001 From: Hsiaoming Yang Date: Tue, 1 May 2018 14:35:55 +0900 Subject: [PATCH 1/6] Fix blueprint route for "" --- flask/blueprints.py | 5 ++++- tests/test_blueprints.py | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/flask/blueprints.py b/flask/blueprints.py index 3bdb3d9e..74bca275 100644 --- a/flask/blueprints.py +++ b/flask/blueprints.py @@ -66,7 +66,10 @@ class BlueprintSetupState(object): blueprint's name. """ if self.url_prefix is not None: - rule = '/'.join((self.url_prefix, rule.lstrip('/'))) + if rule: + rule = '/'.join((self.url_prefix, rule.lstrip('/'))) + else: + rule = self.url_prefix options.setdefault('subdomain', self.subdomain) if endpoint is None: endpoint = _endpoint_from_view_func(view_func) diff --git a/tests/test_blueprints.py b/tests/test_blueprints.py index 46364cab..311d77f6 100644 --- a/tests/test_blueprints.py +++ b/tests/test_blueprints.py @@ -116,6 +116,7 @@ def test_blueprint_app_error_handling(app, client): @pytest.mark.parametrize(('prefix', 'rule', 'url'), ( + ('/foo', '', '/foo'), ('/foo/', '/bar', '/foo/bar'), ('/foo/', 'bar', '/foo/bar'), ('/foo', '/bar', '/foo/bar'), From b21b4d1608f5d83d7d6f503672f7eff46ed28f95 Mon Sep 17 00:00:00 2001 From: David Lord Date: Tue, 1 May 2018 13:29:48 -0700 Subject: [PATCH 2/6] add more merge cases --- flask/blueprints.py | 6 +++--- tests/test_blueprints.py | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/flask/blueprints.py b/flask/blueprints.py index 74bca275..5ce5561e 100644 --- a/flask/blueprints.py +++ b/flask/blueprints.py @@ -10,6 +10,7 @@ :license: BSD, see LICENSE for more details. """ from functools import update_wrapper +from werkzeug.urls import url_join from .helpers import _PackageBoundObject, _endpoint_from_view_func @@ -49,8 +50,6 @@ class BlueprintSetupState(object): url_prefix = self.options.get('url_prefix') if url_prefix is None: url_prefix = self.blueprint.url_prefix - if url_prefix: - url_prefix = url_prefix.rstrip('/') #: The prefix that should be used for all URLs defined on the #: blueprint. self.url_prefix = url_prefix @@ -67,7 +66,8 @@ class BlueprintSetupState(object): """ if self.url_prefix is not None: if rule: - rule = '/'.join((self.url_prefix, rule.lstrip('/'))) + rule = '/'.join(( + self.url_prefix.rstrip('/'), rule.lstrip('/'))) else: rule = self.url_prefix options.setdefault('subdomain', self.subdomain) diff --git a/tests/test_blueprints.py b/tests/test_blueprints.py index 311d77f6..465079cd 100644 --- a/tests/test_blueprints.py +++ b/tests/test_blueprints.py @@ -116,7 +116,12 @@ def test_blueprint_app_error_handling(app, client): @pytest.mark.parametrize(('prefix', 'rule', 'url'), ( + ('', '/', '/'), + ('/', '', '/'), + ('/', '/', '/'), ('/foo', '', '/foo'), + ('/foo/', '', '/foo/'), + ('', '/bar', '/bar'), ('/foo/', '/bar', '/foo/bar'), ('/foo/', 'bar', '/foo/bar'), ('/foo', '/bar', '/foo/bar'), From b4e092600dc2cfd5326a373b4b9fd757a5d8a61a Mon Sep 17 00:00:00 2001 From: Grey Li Date: Wed, 2 May 2018 17:08:31 +0800 Subject: [PATCH 3/6] Check whether exist registered routes --- flask/cli.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/flask/cli.py b/flask/cli.py index 635abb13..efc1733e 100644 --- a/flask/cli.py +++ b/flask/cli.py @@ -825,6 +825,10 @@ def routes_command(sort, all_methods): """Show all registered routes with endpoints and methods.""" rules = list(current_app.url_map.iter_rules()) + if not rules: + click.echo('No routes were registered.') + return + ignored_methods = set(() if all_methods else ('HEAD', 'OPTIONS')) if sort in ('endpoint', 'rule'): From 4dc3ba528147822fc38efc03c5f11dfeaa7c8d13 Mon Sep 17 00:00:00 2001 From: David Lord Date: Wed, 2 May 2018 07:14:08 -0700 Subject: [PATCH 4/6] release 1.0.2 --- CHANGES.rst | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 7ec675df..79d9b5c5 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -7,13 +7,21 @@ Flask Changelog Version 1.0.2 ------------- -Unreleased +Released on May 2nd 2018 + +- Fix more backwards compatibility issues with merging slashes between + a blueprint prefix and route. (`#2748`_) +- Fix error with ``flask routes`` command when there are no routes. + (`#2751`_) + +.. _#2748: https://github.com/pallets/flask/pull/2748 +.. _#2751: https://github.com/pallets/flask/issues/2751 Version 1.0.1 ------------- -Released on April 29 2018 +Released on April 29th 2018 - Fix registering partials (with no ``__name__``) as view functions. (`#2730`_) From dfd3619d6f8796d48fc4e32f819cec9e8aa59156 Mon Sep 17 00:00:00 2001 From: David Lord Date: Wed, 2 May 2018 07:16:14 -0700 Subject: [PATCH 5/6] Bump version number to 1.0.2 --- flask/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flask/__init__.py b/flask/__init__.py index 497f687a..ded19822 100644 --- a/flask/__init__.py +++ b/flask/__init__.py @@ -10,7 +10,7 @@ :license: BSD, see LICENSE for more details. """ -__version__ = '1.0.2.dev' +__version__ = '1.0.2' # utilities we import from Werkzeug and Jinja2 that are unused # in the module but are exported as public interface. From 939c77a39ada26395c033d9f84923b02cef2ae56 Mon Sep 17 00:00:00 2001 From: David Lord Date: Wed, 2 May 2018 07:16:58 -0700 Subject: [PATCH 6/6] Bump version number to 1.0.3.dev --- CHANGES.rst | 6 ++++++ flask/__init__.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 79d9b5c5..fd4e0533 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,12 @@ Flask Changelog =============== +Version 1.0.3 +------------- + +Unreleased + + Version 1.0.2 ------------- diff --git a/flask/__init__.py b/flask/__init__.py index ded19822..6e475ed1 100644 --- a/flask/__init__.py +++ b/flask/__init__.py @@ -10,7 +10,7 @@ :license: BSD, see LICENSE for more details. """ -__version__ = '1.0.2' +__version__ = '1.0.3.dev' # utilities we import from Werkzeug and Jinja2 that are unused # in the module but are exported as public interface.