Skip to content

Commit 28c3e40

Browse files
authored
Merge pull request #44015 from nextcloud/fix/remove-oc-json-encode-usages
fix: Remove calls to deprecated OC_JSON::encode
2 parents 9bb3d87 + ead574b commit 28c3e40

3 files changed

Lines changed: 4 additions & 16 deletions

File tree

lib/private/legacy/OC_API.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public static function renderResult($format, $meta, $data) {
171171
],
172172
];
173173
if ($format == 'json') {
174-
return OC_JSON::encode($response);
174+
return json_encode($response, JSON_HEX_TAG);
175175
}
176176

177177
$writer = new XMLWriter();

lib/private/legacy/OC_EventSource.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ public function send($type, $data = null) {
113113
}
114114
if ($this->fallback) {
115115
$response = '<script type="text/javascript">window.parent.OC.EventSource.fallBackCallBack('
116-
. $this->fallBackId . ',"' . $type . '",' . OC_JSON::encode($data) . ')</script>' . PHP_EOL;
116+
. $this->fallBackId . ',"' . ($type ?? '') . '",' . json_encode($data, JSON_HEX_TAG) . ')</script>' . PHP_EOL;
117117
echo $response;
118118
} else {
119119
if ($type) {
120120
echo 'event: ' . $type . PHP_EOL;
121121
}
122-
echo 'data: ' . OC_JSON::encode($data) . PHP_EOL;
122+
echo 'data: ' . json_encode($data, JSON_HEX_TAG) . PHP_EOL;
123123
}
124124
echo PHP_EOL;
125125
flush();

lib/private/legacy/OC_JSON.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,23 +113,11 @@ public static function success($data = []) {
113113
echo self::encode($data);
114114
}
115115

116-
/**
117-
* Convert OC_L10N_String to string, for use in json encodings
118-
*/
119-
protected static function to_string(&$value) {
120-
if ($value instanceof \OC\L10N\L10NString) {
121-
$value = (string)$value;
122-
}
123-
}
124-
125116
/**
126117
* Encode JSON
127118
* @deprecated Use a AppFramework JSONResponse instead
128119
*/
129-
public static function encode($data) {
130-
if (is_array($data)) {
131-
array_walk_recursive($data, ['OC_JSON', 'to_string']);
132-
}
120+
private static function encode($data) {
133121
return json_encode($data, JSON_HEX_TAG);
134122
}
135123
}

0 commit comments

Comments
 (0)