From a101cfc35be437ad0e4f56da0d92f14c27abda67 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Wed, 29 Jun 2011 18:31:48 +0200 Subject: [PATCH] Worked around a werkzeug bug with redirects --- CHANGES | 1 + flask/app.py | 6 ++++++ tests/flask_tests.py | 15 +++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/CHANGES b/CHANGES index 1e559167..e611c4ab 100644 --- a/CHANGES +++ b/CHANGES @@ -9,6 +9,7 @@ Version 0.7.1 Bugfix release, release date to be decided. - Added missing future import that broke 2.5 compatibility. +- Fixed an infinite redirect issue with blueprints. Version 0.7 ----------- diff --git a/flask/app.py b/flask/app.py index eb7ba023..dff4272b 100644 --- a/flask/app.py +++ b/flask/app.py @@ -706,6 +706,12 @@ class Flask(_PackageBoundObject): if 'OPTIONS' not in methods: methods = tuple(methods) + ('OPTIONS',) provide_automatic_options = True + + # due to a werkzeug bug we need to make sure that the defaults are + # None if they are an empty dictionary. This should not be necessary + # with Werkzeug 0.7 + options['defaults'] = options.get('defaults') or None + rule = self.url_rule_class(rule, methods=methods, **options) rule.provide_automatic_options = provide_automatic_options self.url_map.add(rule) diff --git a/tests/flask_tests.py b/tests/flask_tests.py index e04c2458..fc99cd16 100644 --- a/tests/flask_tests.py +++ b/tests/flask_tests.py @@ -1364,6 +1364,21 @@ class BlueprintTestCase(unittest.TestCase): self.assertEqual(c.get('/fe2').data.strip(), '/fe') self.assertEqual(c.get('/be').data.strip(), '/fe') + def test_empty_url_defaults(self): + bp = flask.Blueprint('bp', __name__) + + @bp.route('/', defaults={'page': 1}) + @bp.route('/page/') + def something(page): + return str(page) + + app = flask.Flask(__name__) + app.register_blueprint(bp) + + c = app.test_client() + self.assertEqual(c.get('/').data, '1') + self.assertEqual(c.get('/page/2').data, '2') + class SendfileTestCase(unittest.TestCase):