Skip to content

Commit

Permalink
fix(AppAPIService): encode query parameter arrays via http_build_query (
Browse files Browse the repository at this point in the history
#412)

Resolves #384. If the checks still pass and this gets merged, perhaps we
should take a look at other apps to see if they need to be updated in
the same way.

Signed-off-by: Edward Ly <contact@edward.ly>
Co-authored-by: Alexander Piskun <13381981+bigcat88@users.noreply.github.com>
  • Loading branch information
edward-ly and bigcat88 authored Oct 8, 2024
1 parent 9061b82 commit f15c6ea
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions lib/Service/AppAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private function prepareRequestToExApp(

if ((!array_key_exists('multipart', $options)) && (count($params)) > 0) {
if ($method === 'GET') {
$url .= '?' . $this->getUriEncodedParams($params);
$url .= '?' . http_build_query($params);
} else {
$options['json'] = $params;
}
Expand Down Expand Up @@ -231,7 +231,7 @@ private function prepareRequestToExApp2(

if ((!array_key_exists('multipart', $options))) {
if (count($queryParams) > 0) {
$url .= '?' . $this->getUriEncodedParams($queryParams);
$url .= '?' . http_build_query($queryParams);
}
if ($method !== 'GET' && count($bodyParams) > 0) {
$options['json'] = $bodyParams;
Expand All @@ -258,19 +258,6 @@ private function swapAuthorizationHeader(array $headers): array {
return $headers;
}

private function getUriEncodedParams(array $params): string {
$paramsContent = '';
foreach ($params as $key => $value) {
if (is_array($value)) {
foreach ($value as $oneArrayValue) {
$paramsContent .= $key . '[]=' . urlencode($oneArrayValue) . '&';
}
unset($params[$key]);
}
}
return $paramsContent . http_build_query($params);
}

/**
* AppAPI authentication request validation for Nextcloud:
* - checks if ExApp exists and is enabled
Expand Down

0 comments on commit f15c6ea

Please sign in to comment.