aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/AppFramework/OCS
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/AppFramework/OCS')
-rw-r--r--lib/private/AppFramework/OCS/BaseResponse.php21
-rw-r--r--lib/private/AppFramework/OCS/V1Response.php7
-rw-r--r--lib/private/AppFramework/OCS/V2Response.php7
3 files changed, 23 insertions, 12 deletions
diff --git a/lib/private/AppFramework/OCS/BaseResponse.php b/lib/private/AppFramework/OCS/BaseResponse.php
index 3b0a28fe89c..05ce133db24 100644
--- a/lib/private/AppFramework/OCS/BaseResponse.php
+++ b/lib/private/AppFramework/OCS/BaseResponse.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -11,10 +12,10 @@ use OCP\AppFramework\Http\Response;
/**
* @psalm-import-type DataResponseType from DataResponse
- * @template S of int
+ * @template S of Http::STATUS_*
* @template-covariant T of DataResponseType
* @template H of array<string, mixed>
- * @template-extends Response<int, array<string, mixed>>
+ * @template-extends Response<Http::STATUS_*, array<string, mixed>>
*/
abstract class BaseResponse extends Response {
/** @var array */
@@ -83,9 +84,9 @@ abstract class BaseResponse extends Response {
*/
protected function renderResult(array $meta): string {
$status = $this->getStatus();
- if ($status === Http::STATUS_NO_CONTENT ||
- $status === Http::STATUS_NOT_MODIFIED ||
- ($status >= 100 && $status <= 199)) {
+ if ($status === Http::STATUS_NO_CONTENT
+ || $status === Http::STATUS_NOT_MODIFIED
+ || ($status >= 100 && $status <= 199)) {
// Those status codes are not supposed to have a body:
// https://stackoverflow.com/q/8628725
return '';
@@ -99,7 +100,7 @@ abstract class BaseResponse extends Response {
];
if ($this->format === 'json') {
- return json_encode($response, JSON_HEX_TAG);
+ return $this->toJson($response);
}
$writer = new \XMLWriter();
@@ -111,6 +112,14 @@ abstract class BaseResponse extends Response {
return $writer->outputMemory(true);
}
+ /**
+ * @psalm-taint-escape has_quotes
+ * @psalm-taint-escape html
+ */
+ protected function toJson(array $array): string {
+ return \json_encode($array, \JSON_HEX_TAG);
+ }
+
protected function toXML(array $array, \XMLWriter $writer): void {
foreach ($array as $k => $v) {
if ($k === '@attributes' && is_array($v)) {
diff --git a/lib/private/AppFramework/OCS/V1Response.php b/lib/private/AppFramework/OCS/V1Response.php
index c56aa9cf478..1c2c25f5cb0 100644
--- a/lib/private/AppFramework/OCS/V1Response.php
+++ b/lib/private/AppFramework/OCS/V1Response.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -11,17 +12,17 @@ use OCP\AppFramework\OCSController;
/**
* @psalm-import-type DataResponseType from DataResponse
- * @template S of int
+ * @template S of Http::STATUS_*
* @template-covariant T of DataResponseType
* @template H of array<string, mixed>
- * @template-extends BaseResponse<int, DataResponseType, array<string, mixed>>
+ * @template-extends BaseResponse<Http::STATUS_*, DataResponseType, array<string, mixed>>
*/
class V1Response extends BaseResponse {
/**
* The V1 endpoint has very limited http status codes basically everything
* is status 200 except 401
*
- * @return int
+ * @return Http::STATUS_*
*/
public function getStatus() {
$status = parent::getStatus();
diff --git a/lib/private/AppFramework/OCS/V2Response.php b/lib/private/AppFramework/OCS/V2Response.php
index caa8302a673..efc9348eb37 100644
--- a/lib/private/AppFramework/OCS/V2Response.php
+++ b/lib/private/AppFramework/OCS/V2Response.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -11,17 +12,17 @@ use OCP\AppFramework\OCSController;
/**
* @psalm-import-type DataResponseType from DataResponse
- * @template S of int
+ * @template S of Http::STATUS_*
* @template-covariant T of DataResponseType
* @template H of array<string, mixed>
- * @template-extends BaseResponse<int, DataResponseType, array<string, mixed>>
+ * @template-extends BaseResponse<Http::STATUS_*, DataResponseType, array<string, mixed>>
*/
class V2Response extends BaseResponse {
/**
* The V2 endpoint just passes on status codes.
* Of course we have to map the OCS specific codes to proper HTTP status codes
*
- * @return int
+ * @return Http::STATUS_*
*/
public function getStatus() {
$status = parent::getStatus();