Browse Source

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

pull/1290/head
Michael Hall 10 years ago
parent
commit
98b155c65d
  1. 2
      flask/app.py
  2. 12
      tests/test_basic.py

2
flask/app.py

@ -998,7 +998,7 @@ class Flask(_PackageBoundObject):
if isinstance(methods, string_types):
raise TypeError('Allowed methods have to be iterables of strings, '
'for example: @app.route(..., methods=["POST"])')
methods = set(methods)
methods = set(item.upper() for item in methods)
# Methods that should always be added
required_methods = set(getattr(view_func, 'required_methods', ()))

12
tests/test_basic.py

@ -107,15 +107,24 @@ def test_disallow_string_for_allowed_methods():
def test_url_mapping():
app = flask.Flask(__name__)
random_uuid4 = "7eb41166-9ebf-4d26-b771-ea3f54f8b383"
def index():
return flask.request.method
def more():
return flask.request.method
def options():
return random_uuid4
app.add_url_rule('/', 'index', index)
app.add_url_rule('/more', 'more', more, methods=['GET', 'POST'])
# Issue 1288: Test that automatic options are not added when non-uppercase 'options' in methods
app.add_url_rule('/options', 'options', options, methods=['options'])
c = app.test_client()
assert c.get('/').data == b'GET'
rv = c.post('/')
@ -129,6 +138,9 @@ def test_url_mapping():
rv = c.delete('/more')
assert rv.status_code == 405
assert sorted(rv.allow) == ['GET', 'HEAD', 'OPTIONS', 'POST']
rv = c.open('/options', method='OPTIONS')
assert rv.status_code == 200
assert random_uuid4 in rv.data.decode("utf-8")
def test_werkzeug_routing():

Loading…
Cancel
Save