Skip to content

Commit 2e17ad7

Browse files
committed
Merge pull request pallets#816 from untitaker/allowed_methods
Fix pallets#815
2 parents 3e4dbf9 + af5a085 commit 2e17ad7

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

flask/app.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,9 @@ def index():
949949
# a tuple of only `GET` as default.
950950
if methods is None:
951951
methods = getattr(view_func, 'methods', None) or ('GET',)
952+
if isinstance(methods, string_types):
953+
raise TypeError('Allowed methods have to be iterables of strings, '
954+
'for example: @app.route(..., methods=["POST"])')
952955
methods = set(methods)
953956

954957
# Methods that should always be added

flask/testsuite/basic.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ def more():
8585
self.assert_equal(rv.status_code, 405)
8686
self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS', 'POST'])
8787

88+
def test_disallow_string_for_allowed_methods(self):
89+
app = flask.Flask(__name__)
90+
with self.assert_raises(TypeError):
91+
@app.route('/', methods='GET POST')
92+
def index():
93+
return "Hey"
94+
8895
def test_url_mapping(self):
8996
app = flask.Flask(__name__)
9097
def index():

0 commit comments

Comments
 (0)