Skip to content

Commit

Permalink
Merge pull request #36696 from nextcloud/backport/36525/stable25
Browse files Browse the repository at this point in the history
[stable25] fix: Only get params from PUT content if possible
  • Loading branch information
nickvergessen authored Feb 24, 2023
2 parents e884498 + 119babd commit a01f4ce
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/private/AppFramework/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ public function __get($name) {
: null;
case 'parameters':
case 'params':
if ($this->isPutStreamContent()) {
return $this->items['parameters'];
}
return $this->getContent();
default:
return isset($this[$name])
Expand Down Expand Up @@ -399,12 +402,7 @@ public function getCookie(string $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') !== ''
&& strpos($this->getHeader('Content-Type'), 'application/x-www-form-urlencoded') === false
&& strpos($this->getHeader('Content-Type'), 'application/json') === false
) {
if ($this->isPutStreamContent()) {
if ($this->content === false) {
throw new \LogicException(
'"put" can only be accessed once if not '
Expand All @@ -419,6 +417,14 @@ protected function getContent() {
}
}

private function isPutStreamContent(): bool {
return $this->method === 'PUT'
&& $this->getHeader('Content-Length') !== '0'
&& $this->getHeader('Content-Length') !== ''
&& strpos($this->getHeader('Content-Type'), 'application/x-www-form-urlencoded') === false
&& strpos($this->getHeader('Content-Type'), 'application/json') === false;
}

/**
* Attempt to decode the content and populate parameters
*/
Expand Down

0 comments on commit a01f4ce

Please sign in to comment.