diff --git a/flask/wrappers.py b/flask/wrappers.py index 8db1ca9a..e592cc28 100644 --- a/flask/wrappers.py +++ b/flask/wrappers.py @@ -80,7 +80,7 @@ class Request(RequestBase): def blueprint(self): """The name of the current blueprint""" if self.url_rule and '.' in self.url_rule.endpoint: - return self.url_rule.endpoint.split('.', 1)[0] + return self.url_rule.endpoint.rsplit('.', 1)[0] @cached_property def json(self): diff --git a/tests/flask_tests.py b/tests/flask_tests.py index 9a0905c1..dae687dd 100644 --- a/tests/flask_tests.py +++ b/tests/flask_tests.py @@ -1323,6 +1323,31 @@ class BlueprintTestCase(unittest.TestCase): with flask.Flask(__name__).test_request_context(): assert flask.render_template('nested/nested.txt') == 'I\'m nested' + def test_dotted_names(self): + frontend = flask.Blueprint('myapp.frontend', __name__) + backend = flask.Blueprint('myapp.backend', __name__) + + @frontend.route('/fe') + def frontend_index(): + return flask.url_for('myapp.backend.backend_index') + + @frontend.route('/fe2') + def frontend_page2(): + return flask.url_for('.frontend_index') + + @backend.route('/be') + def backend_index(): + return flask.url_for('myapp.frontend.frontend_index') + + app = flask.Flask(__name__) + app.register_blueprint(frontend) + app.register_blueprint(backend) + + c = app.test_client() + self.assertEqual(c.get('/fe').data.strip(), '/be') + self.assertEqual(c.get('/fe2').data.strip(), '/fe') + self.assertEqual(c.get('/be').data.strip(), '/fe') + class SendfileTestCase(unittest.TestCase):