Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

fix for https://github.com/mitsuhiko/flask/issues/494 #497

Merged
merged 2 commits into from

3 participants

@ekoka

Flask.inject_url_defaults() incorrectly splits endpoint's to get blueprint's name.

replaced call to endpoint.split() by endpoint.rsplit() on line 1471 of flask/app.py

@rduplain
Collaborator

Thanks for the pull request to fix #494. Could you add a test case to catch the error, which passes with this fix?

@ekoka

Sure, I have one. Do you have a specific convention? i.e. where should I put it? what should I name id?

@ekoka

not exactly sure if this is where the test should go, but there it is.

@mitsuhiko mitsuhiko merged commit a9e753f into mitsuhiko:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 22, 2012
  1. @ekoka

    Update flask/app.py

    ekoka authored
Commits on Apr 24, 2012
  1. @ekoka

    Update flask/testsuite/basic.py

    ekoka authored
This page is out of date. Refresh to see the latest.
Showing with 24 additions and 1 deletion.
  1. +1 −1  flask/app.py
  2. +23 −0 flask/testsuite/basic.py
View
2  flask/app.py
@@ -1468,7 +1468,7 @@ def inject_url_defaults(self, endpoint, values):
"""
funcs = self.url_default_functions.get(None, ())
if '.' in endpoint:
- bp = endpoint.split('.', 1)[0]
+ bp = endpoint.rsplit('.', 1)[0]
funcs = chain(funcs, self.url_default_functions.get(bp, ()))
for func in funcs:
func(endpoint, values)
View
23 flask/testsuite/basic.py
@@ -911,6 +911,29 @@ def something_else():
self.assert_equal(c.get('/de/').data, '/de/about')
self.assert_equal(c.get('/de/about').data, '/foo')
self.assert_equal(c.get('/foo').data, '/en/about')
+
+ def test_inject_blueprint_url_defaults(self):
+ app = flask.Flask(__name__)
+ bp = flask.Blueprint('foo.bar.baz', __name__,
+ template_folder='template')
+
+ @bp.url_defaults
+ def bp_defaults(endpoint, values):
+ values['page'] = 'login'
+ @bp.route('/<page>')
+ def view(page): pass
+
+ app.register_blueprint(bp)
+
+ values = dict()
+ app.inject_url_defaults('foo.bar.baz.view', values)
+ expected = dict(page='login')
+ self.assert_equal(values, expected)
+
+ with app.test_request_context('/somepage'):
+ url = flask.url_for('foo.bar.baz.view')
+ expected = '/login'
+ self.assert_equal(url, expected)
def test_debug_mode_complains_after_first_request(self):
app = flask.Flask(__name__)
Something went wrong with that request. Please try again.