Skip to content

Commit

Permalink
Worked around a werkzeug bug with redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Jun 29, 2011
1 parent c26a6dd commit a101cfc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -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
-----------
Expand Down
6 changes: 6 additions & 0 deletions flask/app.py
Expand Up @@ -706,6 +706,12 @@ def index():
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)
Expand Down
15 changes: 15 additions & 0 deletions tests/flask_tests.py
Expand Up @@ -1364,6 +1364,21 @@ def backend_index():
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/<int: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):

Expand Down

0 comments on commit a101cfc

Please sign in to comment.