Skip to content
Myr

Deny dot's in blueprint endpoints. Add tests for that too.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Pedro Algarvio · committed by Pedro Algarvio · parent 04e87a9 · Browse files · 2 files+53 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+53 added−0 removed

  • tests:+51 added−0 removed
  • other:+2 added−0 removed

2 files+53 added−0 removed

modified:flask/blueprints.py+2 added
164 unmodified lines
165 def add_url_rule(self, rule, endpoint=None, view_func=None, **options):166 """Like :meth:`Flask.add_url_rule` but for a blueprint. The endpoint for167 the :func:`url_for` function is prefixed with the name of the blueprint.168 """169 if endpoint:170 assert '.' not in endpoint, "Blueprint endpoint's should not contain dot's"171 self.record(lambda s:172 s.add_url_rule(rule, endpoint, view_func, **options))173174 def endpoint(self, endpoint):
147 unmodified lines
modified:tests/flask_tests.py+51 added
1745 unmodified lines
1746 self.assertEqual(c.get('/py/bar').data, 'bp.bar')1747 self.assertEqual(c.get('/py/bar/123').data, 'bp.123')1748 self.assertEqual(c.get('/py/bar/foo').data, 'bp.bar_foo')17491750 def test_route_decorator_custom_endpoint_with_dots(self):1751 bp = flask.Blueprint('bp', __name__)17521753 @bp.route('/foo')1754 def foo():1755 return flask.request.endpoint17561757 try:1758 @bp.route('/bar', endpoint='bar.bar')1759 def foo_bar():1760 return flask.request.endpoint1761 except AssertionError:1762 pass1763 else:1764 raise AssertionError('expected AssertionError not raised')17651766 try:1767 @bp.route('/bar/123', endpoint='bar.123')1768 def foo_bar_foo():1769 return flask.request.endpoint1770 except AssertionError:1771 pass1772 else:1773 raise AssertionError('expected AssertionError not raised')17741775 def foo_foo_foo():1776 pass17771778 self.assertRaises(1779 AssertionError,1780 lambda: bp.add_url_rule(1781 '/bar/123', endpoint='bar.123', view_func=foo_foo_foo1782 )1783 )17841785 self.assertRaises(1786 AssertionError,1787 bp.route('/bar/123', endpoint='bar.123'),1788 lambda: None1789 )17901791 app = flask.Flask(__name__)1792 app.register_blueprint(bp, url_prefix='/py')17931794 c = app.test_client()1795 self.assertEqual(c.get('/py/foo').data, 'bp.foo')1796 # The rule's din't actually made it through1797 rv = c.get('/py/bar')1798 assert rv.status_code == 4041799 rv = c.get('/py/bar/123')1800 assert rv.status_code == 40418011802class SendfileTestCase(unittest.TestCase):18031804 def test_send_file_regular(self):1805 app = flask.Flask(__name__)
507 unmodified lines