Skip to content

Commit e429f63

Browse files
committed
forms: do not submit reset inputs
1 parent 912202e commit e429f63

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

scrapy/http/request/form.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def _get_inputs(form, formdata, dont_click, clickdata, response):
9191

9292
inputs = form.xpath('descendant::textarea'
9393
'|descendant::select'
94-
'|descendant::input[@type!="submit" and @type!="image" '
94+
'|descendant::input[@type!="submit" and @type!="image" and @type!="reset"'
9595
'and ((@type!="checkbox" and @type!="radio") or @checked)]')
9696
values = [(k, u'' if v is None else v) \
9797
for k, v in (_value(e) for e in inputs) \

scrapy/tests/test_http_request.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,18 @@ def test_from_response_dont_submit_image_as_input(self):
320320
fs = _qs(req)
321321
self.assertEqual(fs, {'i1': ['i1v']})
322322

323+
def test_from_response_dont_submit_reset_as_input(self):
324+
response = _buildresponse(
325+
"""<form>
326+
<input type="hidden" name="i1" value="i1v">
327+
<input type="text" name="i2" value="i2v">
328+
<input type="reset" name="resetme">
329+
<input type="submit" name="i3" value="i3v">
330+
</form>""")
331+
req = self.request_class.from_response(response, dont_click=True)
332+
fs = _qs(req)
333+
self.assertEqual(fs, {'i1': ['i1v'], 'i2': ['i2v']})
334+
323335
def test_from_response_multiple_clickdata(self):
324336
response = _buildresponse(
325337
"""<form action="get.php" method="GET">

0 commit comments

Comments
 (0)