Skip to content

Commit

Permalink
Allow reading params of PUT more than once
Browse files Browse the repository at this point in the history
  • Loading branch information
VicDeo committed May 15, 2020
1 parent 1e348ec commit f5b5f32
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
7 changes: 7 additions & 0 deletions changelog/unreleased/37394
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Bugfix: Allow unlimited access to PUT body if content length is 0

It was not possible to read more than one URL param of the PUT request with the empty body.
This change checks Content-Length and do not throw the exception on empty request body if
Content-Length states that the empty body had been sent.

https://github.com/owncloud/core/pull/37394
2 changes: 2 additions & 0 deletions lib/private/AppFramework/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,8 @@ public function getCookie($key) {
protected function getContent() {
// If the content can't be parsed into an array then return a stream resource.
if ($this->method === 'PUT'
&& $this->getHeader('Content-Length') !== 0
&& $this->getHeader('Content-Length') !== null
&& \strpos($this->getHeader('Content-Type'), 'application/x-www-form-urlencoded') === false
&& \strpos($this->getHeader('Content-Type'), 'application/json') === false
) {
Expand Down
31 changes: 31 additions & 0 deletions tests/lib/AppFramework/Http/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,37 @@ public function testPutStream() {
$this->fail('Expected LogicException.');
}

public function testDoubleGetParamOnPut() {
$vars = [
'method' => 'PUT',
'server' => [],
];

$request = new Request(
$vars,
$this->secureRandom,
$this->config,
$this->csrfTokenManager,
$this->stream
);

// trigger decoding of the request
$request->getParam('foo');

$request->setUrlParameters([
'var1' => 'value1',
'var2' => 'value2'
]);

// it should be possible to get unlimited number of URL parameters
// without reading the request body
$var1 = $request->getParam('var1');
$var2 = $request->getParam('var2');

$this->assertEquals('value1', $var1);
$this->assertEquals('value2', $var2);
}

public function testSetUrlParameters() {
$vars = [
'post' => [],
Expand Down

0 comments on commit f5b5f32

Please sign in to comment.