Skip to content

Commit

Permalink
Do not break with GET requests that have a query string and a Content…
Browse files Browse the repository at this point in the history
…-Type header (#1117)

* Support Plone REST API calls with a query string.

Refs plone/plone.restapi#1611
  • Loading branch information
ale-rt committed May 12, 2023
1 parent 6977b88 commit 741d895
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ https://github.com/zopefoundation/Zope/blob/4.x/CHANGES.rst
5.8.2 (unreleased)
------------------

- Do not break on GET requests that pass a query string
and a `Content-Type` header.
For details see `#1117 <https://github.com/zopefoundation/Zope/pull/1117>`_.

- Implement code change suggestions from CodeQL scanning.

- Added Japanese translations for some Sphinx docs
Expand Down
2 changes: 1 addition & 1 deletion src/ZPublisher/HTTPRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1441,7 +1441,7 @@ def __init__(self, fp, environ):
raise NotImplementedError("request parameters and body")
if fpos is not None:
fp.seek(fpos)
elif url_qs and content_type != "application/x-www-form-urlencoded":
elif url_qs and fp is not None:
raise NotImplementedError("request parameters and body")
fl = []
add_field = fl.append
Expand Down
30 changes: 30 additions & 0 deletions src/ZPublisher/tests/testHTTPRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,36 @@ def test_bytes_converter(self):
req.processInputs()
self.assertEqual(req.form["a"], val)

def test_get_with_body_and_query_string_ignores_body(self):
req_factory = self._getTargetClass()
req = req_factory(
BytesIO(b"foo"),
{
"SERVER_NAME": "localhost",
"SERVER_PORT": "8080",
"REQUEST_METHOD": "GET",
"QUERY_STRING": "bar"
},
None,
)
req.processInputs()
self.assertDictEqual(req.form, {"bar": ""})

def test_put_with_body_and_query_string_raises(self):
req_factory = self._getTargetClass()
req = req_factory(
BytesIO(b"foo"),
{
"SERVER_NAME": "localhost",
"SERVER_PORT": "8080",
"REQUEST_METHOD": "PUT",
"QUERY_STRING": "bar"
},
None,
)
with self.assertRaises(NotImplementedError):
req.processInputs()

def test_issue_1095(self):
body = TEST_ISSUE_1095_DATA
env = self._makePostEnviron(body)
Expand Down

0 comments on commit 741d895

Please sign in to comment.