From 98b155c65da62077dc5f277a3ec15d3af78333af Mon Sep 17 00:00:00 2001 From: Michael Hall Date: Wed, 24 Dec 2014 11:16:57 -0500 Subject: [PATCH] Fixed #1288: app.add_url_rule() should look for OPTIONS methods in a case-insensitive manner --- flask/app.py | 2 +- tests/test_basic.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/flask/app.py b/flask/app.py index 7532b990..b84c98a7 100644 --- a/flask/app.py +++ b/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', ())) diff --git a/tests/test_basic.py b/tests/test_basic.py index e214aee7..ea66e987 100644 --- a/tests/test_basic.py +++ b/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():