Skip to content

Commit 45e901f

Browse files
committed
Merge pull request pallets#1290 from mhall1/ticket_1288
Fixed pallets#1288: app.add_url_rule() should look for OPTIONS methods in a case-insensitive manner
2 parents b292013 + 98b155c commit 45e901f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

flask/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ def index():
998998
if isinstance(methods, string_types):
999999
raise TypeError('Allowed methods have to be iterables of strings, '
10001000
'for example: @app.route(..., methods=["POST"])')
1001-
methods = set(methods)
1001+
methods = set(item.upper() for item in methods)
10021002

10031003
# Methods that should always be added
10041004
required_methods = set(getattr(view_func, 'required_methods', ()))

tests/test_basic.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,24 @@ def index():
107107
def test_url_mapping():
108108
app = flask.Flask(__name__)
109109

110+
random_uuid4 = "7eb41166-9ebf-4d26-b771-ea3f54f8b383"
111+
110112
def index():
111113
return flask.request.method
112114

113115
def more():
114116
return flask.request.method
115117

118+
def options():
119+
return random_uuid4
120+
121+
116122
app.add_url_rule('/', 'index', index)
117123
app.add_url_rule('/more', 'more', more, methods=['GET', 'POST'])
118124

125+
# Issue 1288: Test that automatic options are not added when non-uppercase 'options' in methods
126+
app.add_url_rule('/options', 'options', options, methods=['options'])
127+
119128
c = app.test_client()
120129
assert c.get('/').data == b'GET'
121130
rv = c.post('/')
@@ -129,6 +138,9 @@ def more():
129138
rv = c.delete('/more')
130139
assert rv.status_code == 405
131140
assert sorted(rv.allow) == ['GET', 'HEAD', 'OPTIONS', 'POST']
141+
rv = c.open('/options', method='OPTIONS')
142+
assert rv.status_code == 200
143+
assert random_uuid4 in rv.data.decode("utf-8")
132144

133145

134146
def test_werkzeug_routing():

0 commit comments

Comments
 (0)