Skip to content
Myr

Fixed #1288: app.add_url_rule() should look for OPTIONS methods in a case-insensitive manner

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

authored by Michael Hall · committed by Michael Hall · parent 413ae61 · Browse files · 2 files+13 added−1 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+13 added−1 removed

  • tests:+12 added−0 removed
  • other:+1 added−1 removed

2 files+13 added−1 removed

modified:flask/app.py+1 added-1 removed
996 unmodified lines
997 methods = getattr(view_func, 'methods', None) or ('GET',)998 if isinstance(methods, string_types):999 raise TypeError('Allowed methods have to be iterables of strings, '1000 'for example: @app.route(..., methods=["POST"])')1001 methods = set(methods)1001 methods = set(item.upper() for item in methods)10021003 # Methods that should always be added1004 required_methods = set(getattr(view_func, 'required_methods', ()))1005
904 unmodified lines
modified:tests/test_basic.py+12 added
105 unmodified lines
106107def test_url_mapping():108 app = flask.Flask(__name__)109110 random_uuid4 = "7eb41166-9ebf-4d26-b771-ea3f54f8b383"111112 def index():113 return flask.request.method114115 def more():116 return flask.request.method117118 def options():119 return random_uuid4120121122 app.add_url_rule('/', 'index', index)123 app.add_url_rule('/more', 'more', more, methods=['GET', 'POST'])124125 # Issue 1288: Test that automatic options are not added when non-uppercase 'options' in methods126 app.add_url_rule('/options', 'options', options, methods=['options'])127128 c = app.test_client()129 assert c.get('/').data == b'GET'130 rv = c.post('/')131 assert rv.status_code == 405
5 unmodified lines
137 assert c.get('/more').data == b'GET'138 rv = c.delete('/more')139 assert rv.status_code == 405140 assert sorted(rv.allow) == ['GET', 'HEAD', 'OPTIONS', 'POST']141 rv = c.open('/options', method='OPTIONS')142 assert rv.status_code == 200143 assert random_uuid4 in rv.data.decode("utf-8")144145146def test_werkzeug_routing():147 from werkzeug.routing import Submount, Rule
1431 unmodified lines