diff --git a/wcfsetup/install/files/acp/update_com.woltlab.wcf_6.2_contactOptions.php b/wcfsetup/install/files/acp/update_com.woltlab.wcf_6.2_contactOptions.php index 831b18cf09c..b3db104f01e 100644 --- a/wcfsetup/install/files/acp/update_com.woltlab.wcf_6.2_contactOptions.php +++ b/wcfsetup/install/files/acp/update_com.woltlab.wcf_6.2_contactOptions.php @@ -6,7 +6,7 @@ use wcf\data\contact\option\ContactOptionEditor; use wcf\data\contact\option\ContactOptionList; -use wcf\util\JSON; + use wcf\util\OptionUtil; $contactOptionList = new ContactOptionList(); @@ -39,7 +39,7 @@ $editor = new ContactOptionEditor($contactOption); $editor->update([ 'optionType' => $optionType, - 'configuration' => JSON::encode($configuration), + 'configuration' => \json_encode($configuration, \JSON_THROW_ON_ERROR), ]); } @@ -57,5 +57,5 @@ function convertSelectOptions(string $selectOptions): string ]; } - return JSON::encode($options); + return \json_encode($options, \JSON_THROW_ON_ERROR); } diff --git a/wcfsetup/install/files/lib/acp/action/WorkerProxyAction.class.php b/wcfsetup/install/files/lib/acp/action/WorkerProxyAction.class.php index f72c6d4d582..860835dd16c 100644 --- a/wcfsetup/install/files/lib/acp/action/WorkerProxyAction.class.php +++ b/wcfsetup/install/files/lib/acp/action/WorkerProxyAction.class.php @@ -8,7 +8,6 @@ use wcf\system\exception\SystemException; use wcf\system\WCF; use wcf\system\worker\IWorker; -use wcf\util\JSON; /** * Handles worker actions. @@ -143,7 +142,7 @@ protected function sendResponse($progress = 0, ?array $parameters = null, $proce // send JSON-encoded response \header('Content-type: application/json; charset=UTF-8'); - echo JSON::encode($returnValues); + echo \json_encode($returnValues, \JSON_THROW_ON_ERROR); exit; } diff --git a/wcfsetup/install/files/lib/acp/form/AbstractFormOptionAddForm.class.php b/wcfsetup/install/files/lib/acp/form/AbstractFormOptionAddForm.class.php index 917e6870f15..79a73afbe9f 100644 --- a/wcfsetup/install/files/lib/acp/form/AbstractFormOptionAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/AbstractFormOptionAddForm.class.php @@ -12,7 +12,6 @@ use wcf\system\form\builder\IFormDocument; use wcf\system\form\option\FormOptionHandler; use wcf\system\form\option\SharedConfigurationFormFields; -use wcf\util\JSON; /** * Default implementation for a form that adds custom options based on the form option system. @@ -47,7 +46,7 @@ function (IFormDocument $document, array $parameters) { } } - $parameters['data']['configuration'] = JSON::encode($configuration); + $parameters['data']['configuration'] = \json_encode($configuration, \JSON_THROW_ON_ERROR); return $parameters; }, @@ -56,7 +55,7 @@ function (IFormDocument $document, array $data, IStorableObject $object) { // @phpstan-ignore property.notFound if ($object->configuration) { - $data = \array_merge($data, JSON::decode($object->configuration)); + $data = \array_merge($data, \json_decode($object->configuration, true, flags: \JSON_THROW_ON_ERROR)); } return $data; diff --git a/wcfsetup/install/files/lib/action/AJAXFileDeleteAction.class.php b/wcfsetup/install/files/lib/action/AJAXFileDeleteAction.class.php index eb62ecb3a48..951132bbe85 100644 --- a/wcfsetup/install/files/lib/action/AJAXFileDeleteAction.class.php +++ b/wcfsetup/install/files/lib/action/AJAXFileDeleteAction.class.php @@ -6,7 +6,6 @@ use wcf\system\exception\UserInputException; use wcf\system\file\upload\UploadFile; use wcf\system\file\upload\UploadHandler; -use wcf\util\JSON; /** * Copy of the default implementation for file uploads using the AJAX-API. @@ -97,7 +96,7 @@ public function execute() */ protected function sendJsonResponse(array $data) { - $json = JSON::encode($data); + $json = \json_encode($data, \JSON_THROW_ON_ERROR); // send JSON response \header('Content-type: application/json; charset=UTF-8'); diff --git a/wcfsetup/install/files/lib/action/AJAXFileUploadAction.class.php b/wcfsetup/install/files/lib/action/AJAXFileUploadAction.class.php index 41abe4c9f05..e78bd26b51a 100644 --- a/wcfsetup/install/files/lib/action/AJAXFileUploadAction.class.php +++ b/wcfsetup/install/files/lib/action/AJAXFileUploadAction.class.php @@ -9,7 +9,6 @@ use wcf\system\WCF; use wcf\util\FileUtil; use wcf\util\ImageUtil; -use wcf\util\JSON; /** * Copy of the default implementation for file uploads using the AJAX-API. @@ -153,7 +152,7 @@ public function execute() */ protected function sendJsonResponse(array $data) { - $json = JSON::encode($data); + $json = \json_encode($data, \JSON_THROW_ON_ERROR); // send JSON response \header('Content-type: application/json; charset=UTF-8'); diff --git a/wcfsetup/install/files/lib/action/AJAXInvokeAction.class.php b/wcfsetup/install/files/lib/action/AJAXInvokeAction.class.php index ea065c757c4..af95241664c 100644 --- a/wcfsetup/install/files/lib/action/AJAXInvokeAction.class.php +++ b/wcfsetup/install/files/lib/action/AJAXInvokeAction.class.php @@ -11,7 +11,6 @@ use wcf\system\IAJAXInvokeAction; use wcf\system\SingletonFactory; use wcf\system\WCF; -use wcf\util\JSON; use wcf\util\StringUtil; /** @@ -168,7 +167,7 @@ protected function invoke() protected function sendResponse() { \header('Content-type: application/json; charset=UTF-8'); - echo JSON::encode($this->response); + echo \json_encode($this->response, \JSON_THROW_ON_ERROR); exit; } diff --git a/wcfsetup/install/files/lib/action/AbstractAjaxAction.class.php b/wcfsetup/install/files/lib/action/AbstractAjaxAction.class.php index 4452a35525a..3631890b10b 100644 --- a/wcfsetup/install/files/lib/action/AbstractAjaxAction.class.php +++ b/wcfsetup/install/files/lib/action/AbstractAjaxAction.class.php @@ -2,8 +2,6 @@ namespace wcf\action; -use wcf\util\JSON; - /** * @deprecated 5.5 Use PSR-7 responses (e.g. Laminas' JsonResponse). */ @@ -17,7 +15,7 @@ abstract class AbstractAjaxAction extends AbstractAction */ protected function sendJsonResponse(array $data) { - $json = JSON::encode($data); + $json = \json_encode($data, \JSON_THROW_ON_ERROR); // send JSON response \header('Content-type: application/json; charset=UTF-8'); diff --git a/wcfsetup/install/files/lib/action/AbstractOauth2Action.class.php b/wcfsetup/install/files/lib/action/AbstractOauth2Action.class.php index fead01ebd89..35651a6e108 100644 --- a/wcfsetup/install/files/lib/action/AbstractOauth2Action.class.php +++ b/wcfsetup/install/files/lib/action/AbstractOauth2Action.class.php @@ -17,7 +17,6 @@ use wcf\system\user\authentication\oauth\User as OauthUser; use wcf\system\WCF; use wcf\util\HtmlString; -use wcf\util\JSON; /** * Generic implementation to handle the OAuth 2 flow. @@ -182,7 +181,7 @@ protected function codeToAccessToken(string $code): array } } - $parsed = JSON::decode((string)$response->getBody()); + $parsed = \json_decode((string)$response->getBody(), true, flags: \JSON_THROW_ON_ERROR); if (!empty($parsed['error'])) { throw new \Exception(\sprintf( diff --git a/wcfsetup/install/files/lib/action/AbstractOauth2AuthAction.class.php b/wcfsetup/install/files/lib/action/AbstractOauth2AuthAction.class.php index 484946f7e41..f793c0ca011 100644 --- a/wcfsetup/install/files/lib/action/AbstractOauth2AuthAction.class.php +++ b/wcfsetup/install/files/lib/action/AbstractOauth2AuthAction.class.php @@ -30,7 +30,6 @@ use wcf\system\user\authentication\oauth\User as OauthUser; use wcf\system\WCF; use wcf\util\HtmlString; -use wcf\util\JSON; /** * Generic implementation to handle the OAuth 2 flow. @@ -163,7 +162,7 @@ protected function getAccessToken(OAuth2Success $auth2Success): array } } - $parsed = JSON::decode((string)$response->getBody()); + $parsed = \json_decode((string)$response->getBody(), true, flags: \JSON_THROW_ON_ERROR); if (!empty($parsed['error'])) { throw new \Exception( diff --git a/wcfsetup/install/files/lib/action/FacebookAuthAction.class.php b/wcfsetup/install/files/lib/action/FacebookAuthAction.class.php index f61ddcfaff8..546bbca4ce6 100644 --- a/wcfsetup/install/files/lib/action/FacebookAuthAction.class.php +++ b/wcfsetup/install/files/lib/action/FacebookAuthAction.class.php @@ -5,7 +5,6 @@ use GuzzleHttp\Psr7\Request; use wcf\system\request\LinkHandler; use wcf\system\user\authentication\oauth\User as OauthUser; -use wcf\util\JSON; use wcf\util\StringUtil; /** @@ -75,7 +74,7 @@ protected function getUser(array $accessToken): OauthUser 'authorization' => \sprintf('Bearer %s', $accessToken['access_token']), ]); $response = $this->getHttpClient()->send($request); - $parsed = JSON::decode((string)$response->getBody()); + $parsed = \json_decode((string)$response->getBody(), true, flags: \JSON_THROW_ON_ERROR); $parsed['__id'] = $parsed['id']; $parsed['__username'] = $parsed['name']; diff --git a/wcfsetup/install/files/lib/action/GithubAuthAction.class.php b/wcfsetup/install/files/lib/action/GithubAuthAction.class.php index d22c60745c5..0e40e6846ee 100644 --- a/wcfsetup/install/files/lib/action/GithubAuthAction.class.php +++ b/wcfsetup/install/files/lib/action/GithubAuthAction.class.php @@ -7,7 +7,6 @@ use Psr\Http\Message\ResponseInterface; use wcf\system\request\LinkHandler; use wcf\system\user\authentication\oauth\User as OauthUser; -use wcf\util\JSON; use wcf\util\StringUtil; /** @@ -71,7 +70,7 @@ protected function getUser(array $accessToken): OauthUser 'authorization' => \sprintf('Bearer %s', $accessToken['access_token']), ]); $response = $this->getHttpClient()->send($request); - $parsed = JSON::decode((string)$response->getBody()); + $parsed = \json_decode((string)$response->getBody(), true, flags: \JSON_THROW_ON_ERROR); $parsed['__id'] = $parsed['id']; $parsed['__username'] = $parsed['login']; @@ -95,7 +94,7 @@ protected function redirectToRegistration(OauthUser $oauthUser): ResponseInterfa 'authorization' => \sprintf('Bearer %s', $oauthUser["accessToken"]["access_token"]), ]); $response = $this->getHttpClient()->send($request); - $emails = JSON::decode((string)$response->getBody()); + $emails = \json_decode((string)$response->getBody(), true, flags: \JSON_THROW_ON_ERROR); // search primary email $email = $emails[0]['email']; diff --git a/wcfsetup/install/files/lib/action/GoogleAuthAction.class.php b/wcfsetup/install/files/lib/action/GoogleAuthAction.class.php index e2b8de754d3..d2a50a33b42 100644 --- a/wcfsetup/install/files/lib/action/GoogleAuthAction.class.php +++ b/wcfsetup/install/files/lib/action/GoogleAuthAction.class.php @@ -5,7 +5,6 @@ use GuzzleHttp\Psr7\Request; use wcf\system\request\LinkHandler; use wcf\system\user\authentication\oauth\User as OauthUser; -use wcf\util\JSON; use wcf\util\StringUtil; /** @@ -35,7 +34,7 @@ private function getConfiguration(): array $request = new Request('GET', 'https://accounts.google.com/.well-known/openid-configuration'); $response = $this->getHttpClient()->send($request); - $this->configuration = JSON::decode((string)$response->getBody()); + $this->configuration = \json_decode((string)$response->getBody(), true, flags: \JSON_THROW_ON_ERROR); } return $this->configuration; @@ -91,7 +90,7 @@ protected function getUser(array $accessToken): OauthUser 'authorization' => \sprintf('Bearer %s', $accessToken['access_token']), ]); $response = $this->getHttpClient()->send($request); - $parsed = JSON::decode((string)$response->getBody()); + $parsed = \json_decode((string)$response->getBody(), true, flags: \JSON_THROW_ON_ERROR); $parsed['__id'] = $parsed['sub']; $parsed['__username'] = $parsed['name']; diff --git a/wcfsetup/install/files/lib/action/TwitterAuthAction.class.php b/wcfsetup/install/files/lib/action/TwitterAuthAction.class.php index c0512bc43eb..5c89139c0af 100644 --- a/wcfsetup/install/files/lib/action/TwitterAuthAction.class.php +++ b/wcfsetup/install/files/lib/action/TwitterAuthAction.class.php @@ -17,7 +17,6 @@ use wcf\system\user\authentication\oauth\twitter\Success as OAuth2TwitterSuccess; use wcf\system\user\authentication\oauth\User as OauthUser; use wcf\system\WCF; -use wcf\util\JSON; use wcf\util\StringUtil; /** @@ -134,7 +133,7 @@ protected function getUser(array $accessToken): OauthUser ); $response = $this->getHttpClient()->send($request); - $parsed = JSON::decode((string)$response->getBody()); + $parsed = \json_decode((string)$response->getBody(), true, flags: \JSON_THROW_ON_ERROR); $parsed['__id'] = $parsed['id']; $parsed['__username'] = $parsed['name']; if (!empty($parsed['email'])) { diff --git a/wcfsetup/install/files/lib/command/style/CreateManifest.class.php b/wcfsetup/install/files/lib/command/style/CreateManifest.class.php index a8574f7015b..b4fd71c8f27 100644 --- a/wcfsetup/install/files/lib/command/style/CreateManifest.class.php +++ b/wcfsetup/install/files/lib/command/style/CreateManifest.class.php @@ -7,7 +7,6 @@ use wcf\system\io\AtomicWriter; use wcf\system\language\LanguageFactory; use wcf\system\WCF; -use wcf\util\JSON; /** * Generate then `manifest-*.json` files for a style. @@ -43,7 +42,7 @@ public function __invoke(): void "type" => "image/png" ]; } - $icons = JSON::encode($icons); + $icons = \json_encode($icons, \JSON_THROW_ON_ERROR); $originalLanguage = WCF::getLanguage(); try { @@ -51,8 +50,8 @@ public function __invoke(): void // To get the correct landing page url, we need to change the language. WCF::setLanguage($language->languageID); - $title = JSON::encode($language->get(PAGE_TITLE)); - $startUrl = JSON::encode($landingPage->getLink()); + $title = \json_encode($language->get(PAGE_TITLE), \JSON_THROW_ON_ERROR); + $startUrl = \json_encode($landingPage->getLink(), \JSON_THROW_ON_ERROR); // update manifest.json $manifest = <<getBody()); + $data = \json_decode((string)$response->getBody(), true, flags: \JSON_THROW_ON_ERROR); $sql = "INSERT INTO wcf1_blacklist_entry (type, hash, lastSeen, occurrences) VALUES (?, ?, ?, ?) diff --git a/wcfsetup/install/files/lib/data/blacklist/status/BlacklistStatus.class.php b/wcfsetup/install/files/lib/data/blacklist/status/BlacklistStatus.class.php index a157ae2fb20..f1fe715a805 100644 --- a/wcfsetup/install/files/lib/data/blacklist/status/BlacklistStatus.class.php +++ b/wcfsetup/install/files/lib/data/blacklist/status/BlacklistStatus.class.php @@ -8,7 +8,6 @@ use wcf\data\DatabaseObject; use wcf\system\exception\SystemException; use wcf\system\io\HttpFactory; -use wcf\util\JSON; /** * Represents a blacklist status. @@ -113,7 +112,7 @@ public static function getNextDelta(array $status, ?ClientInterface $client = nu return null; } - $data = JSON::decode((string)$response->getBody()); + $data = \json_decode((string)$response->getBody(), true, flags: \JSON_THROW_ON_ERROR); $deltas = ['delta1', 'delta2', 'delta3', 'delta4']; // The array is ordered from "now" to "14 days ago". diff --git a/wcfsetup/install/files/lib/data/contact/option/ContactOption.class.php b/wcfsetup/install/files/lib/data/contact/option/ContactOption.class.php index 75ea37865a8..6a7abb82034 100644 --- a/wcfsetup/install/files/lib/data/contact/option/ContactOption.class.php +++ b/wcfsetup/install/files/lib/data/contact/option/ContactOption.class.php @@ -8,7 +8,6 @@ use wcf\system\form\option\FormOptionHandler; use wcf\system\form\option\IFormOption; use wcf\system\WCF; -use wcf\util\JSON; /** * Represents a contact option. @@ -75,6 +74,6 @@ public function getFormOption(): IFormOption */ public function getConfiguration(): array { - return $this->configuration ? JSON::decode($this->configuration) : []; + return $this->configuration ? \json_decode($this->configuration, true, flags: \JSON_THROW_ON_ERROR) : []; } } diff --git a/wcfsetup/install/files/lib/data/devtools/missing/language/item/DevtoolsMissingLanguageItem.class.php b/wcfsetup/install/files/lib/data/devtools/missing/language/item/DevtoolsMissingLanguageItem.class.php index 05922816fdc..d419fd41ed2 100644 --- a/wcfsetup/install/files/lib/data/devtools/missing/language/item/DevtoolsMissingLanguageItem.class.php +++ b/wcfsetup/install/files/lib/data/devtools/missing/language/item/DevtoolsMissingLanguageItem.class.php @@ -6,7 +6,6 @@ use wcf\data\language\Language; use wcf\system\language\LanguageFactory; use wcf\system\WCF; -use wcf\util\JSON; /** * Represents a missing language item log entry. @@ -47,7 +46,7 @@ public function getLanguage() */ public function getStackTrace() { - $stackTrace = JSON::decode($this->stackTrace); + $stackTrace = \json_decode($this->stackTrace, true, flags: \JSON_THROW_ON_ERROR); return WCF::getTPL()->render('wcf', '__devtoolsMissingLanguageItemStackTrace', [ 'stackTrace' => $stackTrace, diff --git a/wcfsetup/install/files/lib/data/devtools/missing/language/item/DevtoolsMissingLanguageItemAction.class.php b/wcfsetup/install/files/lib/data/devtools/missing/language/item/DevtoolsMissingLanguageItemAction.class.php index d9bcd8c90ae..68173109515 100644 --- a/wcfsetup/install/files/lib/data/devtools/missing/language/item/DevtoolsMissingLanguageItemAction.class.php +++ b/wcfsetup/install/files/lib/data/devtools/missing/language/item/DevtoolsMissingLanguageItemAction.class.php @@ -6,7 +6,6 @@ use wcf\data\IDeleteAction; use wcf\system\exception\IllegalLinkException; use wcf\system\WCF; -use wcf\util\JSON; use wcf\util\StringUtil; /** @@ -70,7 +69,7 @@ public function logLanguageItem() return $item; }, \wcf\functions\exception\sanitizeStacktrace(new \Exception(), true)); - $stackTrace = JSON::encode($stackTraceData); + $stackTrace = \json_encode($stackTraceData, \JSON_THROW_ON_ERROR); $sql = "INSERT INTO wcf1_devtools_missing_language_item (languageID, languageItem, lastTime, stackTrace) diff --git a/wcfsetup/install/files/lib/data/file/File.class.php b/wcfsetup/install/files/lib/data/file/File.class.php index 3b4a04759d2..86b748ef10b 100644 --- a/wcfsetup/install/files/lib/data/file/File.class.php +++ b/wcfsetup/install/files/lib/data/file/File.class.php @@ -12,7 +12,6 @@ use wcf\system\file\processor\IImageDataProvider; use wcf\system\file\processor\ImageData; use wcf\system\request\LinkHandler; -use wcf\util\JSON; use wcf\util\StringUtil; /** @@ -220,8 +219,8 @@ public function toHtmlElement(?array $metaData = null): string StringUtil::encodeHTML($this->filename), $this->fileSize, StringUtil::encodeHTML($this->mimeType), - StringUtil::encodeHTML(JSON::encode($thumbnails)), - $metaData === null ? "" : 'data-meta-data="' . StringUtil::encodeHTML(JSON::encode($metaData)) . '"', + StringUtil::encodeHTML(\json_encode($thumbnails, \JSON_THROW_ON_ERROR)), + $metaData === null ? "" : 'data-meta-data="' . StringUtil::encodeHTML(\json_encode($metaData, \JSON_THROW_ON_ERROR)) . '"', StringUtil::encodeHTML($this->getLink()), ); } diff --git a/wcfsetup/install/files/lib/data/file/FileEditor.class.php b/wcfsetup/install/files/lib/data/file/FileEditor.class.php index d0df7b5398a..cdc5087971f 100644 --- a/wcfsetup/install/files/lib/data/file/FileEditor.class.php +++ b/wcfsetup/install/files/lib/data/file/FileEditor.class.php @@ -11,7 +11,6 @@ use wcf\system\image\ImageHandler; use wcf\util\ExifUtil; use wcf\util\FileUtil; -use wcf\util\JSON; /** * @author Alexander Ebert diff --git a/wcfsetup/install/files/lib/data/file/temporary/FileTemporary.class.php b/wcfsetup/install/files/lib/data/file/temporary/FileTemporary.class.php index 98f41099094..99836c1ad58 100644 --- a/wcfsetup/install/files/lib/data/file/temporary/FileTemporary.class.php +++ b/wcfsetup/install/files/lib/data/file/temporary/FileTemporary.class.php @@ -4,7 +4,6 @@ use wcf\data\DatabaseObject; use wcf\system\file\processor\FileProcessor; -use wcf\util\JSON; /** * @author Alexander Ebert @@ -80,7 +79,7 @@ public function getPathname(): string */ public function getContext(): array { - return JSON::decode($this->context); + return \json_decode($this->context, true, flags: \JSON_THROW_ON_ERROR); } public static function getNumberOfChunks(int $fileSize): int diff --git a/wcfsetup/install/files/lib/data/like/object/LikeObject.class.php b/wcfsetup/install/files/lib/data/like/object/LikeObject.class.php index db0a6b26a85..89cbb8e8b60 100644 --- a/wcfsetup/install/files/lib/data/like/object/LikeObject.class.php +++ b/wcfsetup/install/files/lib/data/like/object/LikeObject.class.php @@ -7,7 +7,6 @@ use wcf\data\reaction\type\ReactionTypeCache; use wcf\data\user\User; use wcf\system\WCF; -use wcf\util\JSON; /** * Represents a liked object. @@ -98,7 +97,7 @@ protected function handleData($data) $this->reactions[$reactionTypeID] = [ 'reactionCount' => $reactionCount, 'renderedReactionIcon' => $reactionType->renderIcon(), - 'renderedReactionIconEncoded' => JSON::encode($reactionType->renderIcon()), + 'renderedReactionIconEncoded' => \json_encode($reactionType->renderIcon(), \JSON_THROW_ON_ERROR), 'reactionTitle' => $reactionType->getTitle(), ]; } @@ -178,7 +177,7 @@ public function getReactionsJson(): string ]; } - return JSON::encode($data); + return \json_encode($data, \JSON_THROW_ON_ERROR); } /** diff --git a/wcfsetup/install/files/lib/data/user/User.class.php b/wcfsetup/install/files/lib/data/user/User.class.php index 84cac1eee3f..fca14c0480a 100644 --- a/wcfsetup/install/files/lib/data/user/User.class.php +++ b/wcfsetup/install/files/lib/data/user/User.class.php @@ -16,7 +16,6 @@ use wcf\system\user\authentication\password\PasswordAlgorithmManager; use wcf\system\user\storage\UserStorageHandler; use wcf\system\WCF; -use wcf\util\JSON; use wcf\util\UserUtil; /** @@ -660,7 +659,7 @@ public function canPurchasePaidSubscriptions() public function getBlacklistMatches() { if ($this->pendingActivation() && $this->blacklistMatches) { - return JSON::decode($this->blacklistMatches); + return \json_decode($this->blacklistMatches, true, flags: \JSON_THROW_ON_ERROR); } return []; diff --git a/wcfsetup/install/files/lib/form/AccountManagementForm.class.php b/wcfsetup/install/files/lib/form/AccountManagementForm.class.php index c154bfe5c3e..fd9fcd92e05 100644 --- a/wcfsetup/install/files/lib/form/AccountManagementForm.class.php +++ b/wcfsetup/install/files/lib/form/AccountManagementForm.class.php @@ -9,12 +9,10 @@ use wcf\system\email\mime\MimePartFacade; use wcf\system\email\mime\RecipientAwareTextMimePart; use wcf\system\email\UserMailbox; -use wcf\system\exception\SystemException; use wcf\system\exception\UserInputException; use wcf\system\menu\user\UserMenu; use wcf\system\user\authentication\configuration\UserAuthenticationConfigurationFactory; use wcf\system\WCF; -use wcf\util\JSON; use wcf\util\StringUtil; use wcf\util\UserRegistrationUtil; @@ -155,8 +153,8 @@ public function readFormParameters() } if (isset($_POST['newPassword_passwordStrengthVerdict'])) { try { - $this->newPasswordStrengthVerdict = JSON::decode($_POST['newPassword_passwordStrengthVerdict']); - } catch (SystemException $e) { + $this->newPasswordStrengthVerdict = \json_decode($_POST['newPassword_passwordStrengthVerdict'], true, flags: \JSON_THROW_ON_ERROR); + } catch (\JsonException) { // ignore } } diff --git a/wcfsetup/install/files/lib/form/NewPasswordForm.class.php b/wcfsetup/install/files/lib/form/NewPasswordForm.class.php index ecc4acb8874..5dbc780d8e4 100644 --- a/wcfsetup/install/files/lib/form/NewPasswordForm.class.php +++ b/wcfsetup/install/files/lib/form/NewPasswordForm.class.php @@ -7,7 +7,6 @@ use wcf\system\exception\IllegalLinkException; use wcf\system\exception\NamedUserException; use wcf\system\exception\PermissionDeniedException; -use wcf\system\exception\SystemException; use wcf\system\form\builder\container\FormContainer; use wcf\system\form\builder\field\PasswordFormField; use wcf\system\form\builder\field\validation\FormFieldValidationError; @@ -17,7 +16,6 @@ use wcf\system\WCF; use wcf\util\HeaderUtil; use wcf\util\HtmlString; -use wcf\util\JSON; use wcf\util\StringUtil; use wcf\util\UserRegistrationUtil; @@ -120,8 +118,8 @@ private function validatePassword(PasswordFormField $formField): void { if (isset($_POST['newPassword_passwordStrengthVerdict'])) { try { - $newPasswordStrengthVerdict = JSON::decode($_POST['newPassword_passwordStrengthVerdict']); - } catch (SystemException $e) { + $newPasswordStrengthVerdict = \json_decode($_POST['newPassword_passwordStrengthVerdict'], true, flags: \JSON_THROW_ON_ERROR); + } catch (\JsonException) { // ignore } } diff --git a/wcfsetup/install/files/lib/form/RegisterForm.class.php b/wcfsetup/install/files/lib/form/RegisterForm.class.php index fc8955d22cd..1a945a2e950 100644 --- a/wcfsetup/install/files/lib/form/RegisterForm.class.php +++ b/wcfsetup/install/files/lib/form/RegisterForm.class.php @@ -29,7 +29,6 @@ use wcf\system\WCF; use wcf\util\HeaderUtil; use wcf\util\HtmlString; -use wcf\util\JSON; use wcf\util\StringUtil; use wcf\util\UserRegistrationUtil; use wcf\util\UserUtil; @@ -169,10 +168,12 @@ public function readFormParameters() } if (isset($_POST[$this->randomFieldNames['password'] . '_passwordStrengthVerdict'])) { try { - $this->passwordStrengthVerdict = JSON::decode( - $_POST[$this->randomFieldNames['password'] . '_passwordStrengthVerdict'] + $this->passwordStrengthVerdict = \json_decode( + $_POST[$this->randomFieldNames['password'] . '_passwordStrengthVerdict'], + true, + flags: \JSON_THROW_ON_ERROR ); - } catch (SystemException $e) { + } catch (\JsonException) { // ignore } } @@ -429,7 +430,7 @@ public function save() 'username' => $this->username, 'email' => $this->email, 'password' => $this->password, - 'blacklistMatches' => $this->spamCheckEvent->hasMatches() ? JSON::encode($this->spamCheckEvent->getMatches()) : '', + 'blacklistMatches' => $this->spamCheckEvent->hasMatches() ? \json_encode($this->spamCheckEvent->getMatches(), \JSON_THROW_ON_ERROR) : '', 'signatureEnableHtml' => 1, ]), 'groups' => $this->groupIDs, diff --git a/wcfsetup/install/files/lib/http/middleware/JsonBody.class.php b/wcfsetup/install/files/lib/http/middleware/JsonBody.class.php index e8514852fbb..f1cc8282f9b 100644 --- a/wcfsetup/install/files/lib/http/middleware/JsonBody.class.php +++ b/wcfsetup/install/files/lib/http/middleware/JsonBody.class.php @@ -8,8 +8,6 @@ use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; -use wcf\system\exception\SystemException; -use wcf\util\JSON; /** * Decodes requests containing a JSON body. @@ -31,8 +29,8 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface $hasValidJson = false; if ($this->contentTypeIsJson($request)) { try { - $data = JSON::decode($request->getBody()); - } catch (SystemException $e) { + $data = \json_decode($request->getBody(), true, flags: \JSON_THROW_ON_ERROR); + } catch (\JsonException) { return new TextResponse('Failed to decode the request body.', 400); } diff --git a/wcfsetup/install/files/lib/system/CLIWCF.class.php b/wcfsetup/install/files/lib/system/CLIWCF.class.php index ed9d2896997..27a4bfbdad7 100644 --- a/wcfsetup/install/files/lib/system/CLIWCF.class.php +++ b/wcfsetup/install/files/lib/system/CLIWCF.class.php @@ -13,7 +13,6 @@ use wcf\system\exception\UserInputException; use wcf\system\user\authentication\UserAuthenticationFactory; use wcf\util\FileUtil; -use wcf\util\JSON; use wcf\util\StringUtil; use Zend\Console\Exception\RuntimeException as ArgvException; use Zend\Console\Getopt as ArgvParser; @@ -285,7 +284,7 @@ protected function initCommands(): void $command = CLICommandHandler::getCommand($line); $command->execute(CLICommandHandler::getParameters($line)); } catch (IllegalLinkException $e) { - Log::error('notFound:' . JSON::encode(['command' => $line])); + Log::error('notFound:' . \json_encode(['command' => $line], \JSON_THROW_ON_ERROR)); self::getReader()->println(WCF::getLanguage()->getDynamicVariable( 'wcf.cli.error.command.notFound', ['command' => $line] diff --git a/wcfsetup/install/files/lib/system/acl/ACLHandler.class.php b/wcfsetup/install/files/lib/system/acl/ACLHandler.class.php index 459e062758f..d3d065e566f 100644 --- a/wcfsetup/install/files/lib/system/acl/ACLHandler.class.php +++ b/wcfsetup/install/files/lib/system/acl/ACLHandler.class.php @@ -15,7 +15,6 @@ use wcf\system\exception\SystemException; use wcf\system\SingletonFactory; use wcf\system\WCF; -use wcf\util\JSON; /** * Handles ACL permissions. @@ -81,7 +80,7 @@ public function assignVariables($objectTypeID) $users = []; foreach ($values as $type => $optionData) { - $optionData = JSON::decode($optionData); + $optionData = \json_decode($optionData, true, flags: \JSON_THROW_ON_ERROR); if ($type === 'user') { $users = User::getUsers(\array_keys($optionData)); } @@ -167,7 +166,7 @@ public function readValues($objectTypeID, ?array $valuesSource = null) if (isset($valuesSource[$type])) { $this->__readValues[$objectTypeID][$type] = []; - foreach (JSON::decode($valuesSource[$type]) as $typeID => $optionData) { + foreach (\json_decode($valuesSource[$type], true, flags: \JSON_THROW_ON_ERROR) as $typeID => $optionData) { $this->__readValues[$objectTypeID][$type][$typeID] = []; foreach ($optionData as $optionID => $optionValue) { @@ -177,7 +176,7 @@ public function readValues($objectTypeID, ?array $valuesSource = null) } } - $this->__readValues[$objectTypeID][$type] = JSON::encode($this->__readValues[$objectTypeID][$type]); + $this->__readValues[$objectTypeID][$type] = \json_encode($this->__readValues[$objectTypeID][$type], \JSON_THROW_ON_ERROR); } } } @@ -282,9 +281,9 @@ protected function replaceValues(ACLOptionList $optionList, $type, $objectID) // add new values if given $values = []; if (isset($this->__readValues[$objectTypeID]) && isset($this->__readValues[$objectTypeID][$type])) { - $values = JSON::decode($this->__readValues[$objectTypeID][$type]); + $values = \json_decode($this->__readValues[$objectTypeID][$type], true, flags: \JSON_THROW_ON_ERROR); } elseif (isset($_POST['aclValues']) && isset($_POST['aclValues'][$type])) { - $values = JSON::decode($_POST['aclValues'][$type]); + $values = \json_decode($_POST['aclValues'][$type], true, flags: \JSON_THROW_ON_ERROR); } $sql = "INSERT INTO wcf1_acl_option_to_" . $type . " diff --git a/wcfsetup/install/files/lib/system/background/job/ServiceWorkerDeliveryBackgroundJob.class.php b/wcfsetup/install/files/lib/system/background/job/ServiceWorkerDeliveryBackgroundJob.class.php index b80c5637f73..0dac0211aad 100644 --- a/wcfsetup/install/files/lib/system/background/job/ServiceWorkerDeliveryBackgroundJob.class.php +++ b/wcfsetup/install/files/lib/system/background/job/ServiceWorkerDeliveryBackgroundJob.class.php @@ -13,7 +13,6 @@ use wcf\system\style\StyleHandler; use wcf\system\user\notification\UserNotificationHandler; use wcf\system\WCF; -use wcf\util\JSON; use wcf\util\StringUtil; /** @@ -114,7 +113,7 @@ private function sendNotification(int $serviceWorkerID, int $notificationID): vo "icon" => $style->getFaviconAppleTouchIcon(), ]; - $report = ServiceWorkerHandler::getInstance()->sendOneNotification($serviceWorker, JSON::encode($content)); + $report = ServiceWorkerHandler::getInstance()->sendOneNotification($serviceWorker, \json_encode($content, \JSON_THROW_ON_ERROR)); if (!$report->isSuccess()) { (new ServiceWorkerEditor($serviceWorker))->delete(); } diff --git a/wcfsetup/install/files/lib/system/bbcode/BBCodeHandler.class.php b/wcfsetup/install/files/lib/system/bbcode/BBCodeHandler.class.php index df3abdd89fc..6b10bcd0cd7 100644 --- a/wcfsetup/install/files/lib/system/bbcode/BBCodeHandler.class.php +++ b/wcfsetup/install/files/lib/system/bbcode/BBCodeHandler.class.php @@ -9,7 +9,6 @@ use wcf\system\SingletonFactory; use wcf\system\WCF; use wcf\util\ArrayUtil; -use wcf\util\JSON; use wcf\util\StringUtil; /** @@ -161,11 +160,11 @@ public function getSourceBBCodes() public function getHighlighterMeta() { if ($this->highlighterMeta === null) { - $this->highlighterMeta = JSON::decode(\preg_replace( + $this->highlighterMeta = \json_decode(\preg_replace( '/.*\/\*!START\*\/\s*const\s*metadata\s*=\s*(.*)\s*;\s*\/\*!END\*\/.*/s', '\\1', \file_get_contents(WCF_DIR . 'js/WoltLabSuite/Core/prism-meta.js') - )); + ), true, flags: \JSON_THROW_ON_ERROR); } return $this->highlighterMeta; diff --git a/wcfsetup/install/files/lib/system/bbcode/DomBBCodeParser.class.php b/wcfsetup/install/files/lib/system/bbcode/DomBBCodeParser.class.php index 616e6c78b9e..9e3b5ad91ab 100644 --- a/wcfsetup/install/files/lib/system/bbcode/DomBBCodeParser.class.php +++ b/wcfsetup/install/files/lib/system/bbcode/DomBBCodeParser.class.php @@ -4,7 +4,6 @@ use wcf\data\bbcode\BBCodeCache; use wcf\system\SingletonFactory; -use wcf\util\JSON; use wcf\util\StringUtil; /** @@ -146,12 +145,12 @@ public function parse(\DOMDocument $document): void } if ($node->hasAttribute('data-attributes')) { - $attributes = JSON::decode(\base64_decode($node->getAttribute('data-attributes'))); + $attributes = \json_decode(\base64_decode($node->getAttribute('data-attributes')), true, flags: \JSON_THROW_ON_ERROR); } else { $attributes = []; } $attributes[$attributeNo] = $text; - $node->setAttribute('data-attributes', \base64_encode(JSON::encode($attributes))); + $node->setAttribute('data-attributes', \base64_encode(\json_encode($attributes, \JSON_THROW_ON_ERROR))); } foreach ($nodes as $node) { $node->parentNode?->removeChild($node); @@ -258,13 +257,13 @@ private function createMetacodeMarker(string $bbcodeTag): ?\DOMElement if ($attributes !== []) { $metacodeMarker->setAttribute( 'data-attributes', - \base64_encode(JSON::encode(\array_map(static function ($attribute) { + \base64_encode(\json_encode(\array_map(static function ($attribute) { if (\preg_match('~^([\'"])(?P.*)(\1)$~', $attribute, $matches)) { return $matches['content']; } return $attribute; - }, $attributes))) + }, $attributes), \JSON_THROW_ON_ERROR)) ); } } diff --git a/wcfsetup/install/files/lib/system/bbcode/HtmlBBCodeParser.class.php b/wcfsetup/install/files/lib/system/bbcode/HtmlBBCodeParser.class.php index 1e5c443ff7d..0865c818ba6 100644 --- a/wcfsetup/install/files/lib/system/bbcode/HtmlBBCodeParser.class.php +++ b/wcfsetup/install/files/lib/system/bbcode/HtmlBBCodeParser.class.php @@ -5,7 +5,6 @@ use wcf\data\bbcode\attribute\BBCodeAttribute; use wcf\system\exception\SystemException; use wcf\util\DOMUtil; -use wcf\util\JSON; use wcf\util\StringUtil; /** @@ -435,7 +434,7 @@ protected function buildOpeningTag(array $tag) }, $tag['attributes']); // uses base64 encoding to avoid an "escape" nightmare - $attributes = ' data-attributes="' . \base64_encode(JSON::encode($tag['attributes'])) . '"'; + $attributes = ' data-attributes="' . \base64_encode(\json_encode($tag['attributes'], \JSON_THROW_ON_ERROR)) . '"'; if (isset($tag['useText'])) { $attributes .= ' data-use-text="' . $tag['useText'] . '"'; diff --git a/wcfsetup/install/files/lib/system/captcha/RecaptchaHandler.class.php b/wcfsetup/install/files/lib/system/captcha/RecaptchaHandler.class.php index 78134d28858..5b46b5eb7ac 100644 --- a/wcfsetup/install/files/lib/system/captcha/RecaptchaHandler.class.php +++ b/wcfsetup/install/files/lib/system/captcha/RecaptchaHandler.class.php @@ -8,7 +8,6 @@ use wcf\system\exception\UserInputException; use wcf\system\io\HttpFactory; use wcf\system\WCF; -use wcf\util\JSON; use wcf\util\UserUtil; /** @@ -136,7 +135,7 @@ public function validate() try { $response = $this->getHttpClient()->send($request); - $data = JSON::decode((string)$response->getBody()); + $data = \json_decode((string)$response->getBody(), true, flags: \JSON_THROW_ON_ERROR); if ($data['success']) { // reCaptcha v3 score ranges from 1.0(very likely a good interaction) and 0.0(very likely a bot), diff --git a/wcfsetup/install/files/lib/system/cli/command/WorkerCLICommand.class.php b/wcfsetup/install/files/lib/system/cli/command/WorkerCLICommand.class.php index 7ddea25c8dd..d406813b2f1 100644 --- a/wcfsetup/install/files/lib/system/cli/command/WorkerCLICommand.class.php +++ b/wcfsetup/install/files/lib/system/cli/command/WorkerCLICommand.class.php @@ -12,7 +12,6 @@ use wcf\system\worker\IWorker; use wcf\util\CLIUtil; use wcf\util\DirectoryUtil; -use wcf\util\JSON; use wcf\util\StringUtil; use Zend\Console\Exception\RuntimeException as ArgvException; use Zend\Console\Getopt as ArgvParser; @@ -171,25 +170,25 @@ public function execute(array $parameters) $progress = $worker->getProgress(); $progressbar->update($progress); if ($output) { - $output->write(JSON::encode([ + $output->write(\json_encode([ 'iteration' => $i, 'progress' => $progress, - ]) . "\n"); + ], \JSON_THROW_ON_ERROR) . "\n"); } } } catch (\Exception $e) { if ($output) { - $output->write(JSON::encode([ + $output->write(\json_encode([ 'error' => (string)$e, - ])); + ], \JSON_THROW_ON_ERROR)); } throw $e; } if ($output) { - $output->write(JSON::encode([ + $output->write(\json_encode([ 'finished' => true, 'progress' => $progress, - ]) . "\n"); + ], \JSON_THROW_ON_ERROR) . "\n"); $output->close(); } $progressbar->update($progress); @@ -324,7 +323,7 @@ protected function spawnController(IWorker $worker, $threads) $statusPrefix = 'T' . $processData['threadId'] . ': '; if ($line) { // If a line could be read we update the progressbar with the data sent. - $parsedLine = JSON::decode(StringUtil::trim($line)); + $parsedLine = \json_decode(StringUtil::trim($line), true, flags: \JSON_THROW_ON_ERROR); if (!empty($parsedLine['error'])) { \fwrite(\STDERR, \str_repeat("\n", -$cursorOffset + 1)); diff --git a/wcfsetup/install/files/lib/system/devtools/DevtoolsSetup.class.php b/wcfsetup/install/files/lib/system/devtools/DevtoolsSetup.class.php index 1b856186a30..ace3bc8665d 100644 --- a/wcfsetup/install/files/lib/system/devtools/DevtoolsSetup.class.php +++ b/wcfsetup/install/files/lib/system/devtools/DevtoolsSetup.class.php @@ -4,7 +4,6 @@ use wcf\system\SingletonFactory; use wcf\util\FileUtil; -use wcf\util\JSON; /** * Enables the rapid deployment of new installations using a central configuration file @@ -71,7 +70,7 @@ protected function init() $contents = \file_get_contents($docRoot . self::CONFIGURATION_FILE); // allow the exception to go rampage - $this->configuration = JSON::decode($contents); + $this->configuration = \json_decode($contents, true, flags: \JSON_THROW_ON_ERROR); } /** diff --git a/wcfsetup/install/files/lib/system/devtools/pip/DevtoolsPip.class.php b/wcfsetup/install/files/lib/system/devtools/pip/DevtoolsPip.class.php index 46dac0918de..abfa092af9d 100644 --- a/wcfsetup/install/files/lib/system/devtools/pip/DevtoolsPip.class.php +++ b/wcfsetup/install/files/lib/system/devtools/pip/DevtoolsPip.class.php @@ -10,7 +10,6 @@ use wcf\system\package\plugin\IPackageInstallationPlugin; use wcf\system\WCF; use wcf\util\FileUtil; -use wcf\util\JSON; /** * Wrapper class for package installation plugins for use with the sync feature. @@ -114,7 +113,7 @@ public function getSyncDependencies($toJson = true) { $dependencies = \call_user_func([$this->getDecoratedObject()->className, 'getSyncDependencies']); - return ($toJson) ? JSON::encode($dependencies) : $dependencies; + return ($toJson) ? \json_encode($dependencies, \JSON_THROW_ON_ERROR) : $dependencies; } /** diff --git a/wcfsetup/install/files/lib/system/endpoint/controller/core/files/PrepareUpload.class.php b/wcfsetup/install/files/lib/system/endpoint/controller/core/files/PrepareUpload.class.php index 65091b343fa..1b3b43111b5 100644 --- a/wcfsetup/install/files/lib/system/endpoint/controller/core/files/PrepareUpload.class.php +++ b/wcfsetup/install/files/lib/system/endpoint/controller/core/files/PrepareUpload.class.php @@ -11,11 +11,9 @@ use wcf\system\endpoint\IController; use wcf\system\endpoint\PostRequest; use wcf\system\exception\PermissionDeniedException; -use wcf\system\exception\SystemException; use wcf\system\exception\UserInputException; use wcf\system\file\processor\FileProcessor; use wcf\system\file\processor\FileProcessorPreflightResult; -use wcf\util\JSON; use WoltLab\WebpExif\Chunk\Exif; /** @@ -39,8 +37,8 @@ public function __invoke(ServerRequestInterface $request, array $variables): Res } try { - $decodedContext = JSON::decode($parameters->context); - } catch (SystemException) { + $decodedContext = \json_decode($parameters->context, true, flags: \JSON_THROW_ON_ERROR); + } catch (\JsonException) { throw new UserInputException('context', 'invalid'); } diff --git a/wcfsetup/install/files/lib/system/exception/AJAXException.class.php b/wcfsetup/install/files/lib/system/exception/AJAXException.class.php index c4eced7d06c..9e265aa4d26 100644 --- a/wcfsetup/install/files/lib/system/exception/AJAXException.class.php +++ b/wcfsetup/install/files/lib/system/exception/AJAXException.class.php @@ -5,7 +5,6 @@ use Throwable; use wcf\system\WCF; use wcf\system\WCFACP; -use wcf\util\JSON; use wcf\util\StringUtil; /** @@ -175,7 +174,7 @@ public function __construct( \header($statusHeader); \header('Content-type: application/json; charset=UTF-8'); - echo JSON::encode($responseData); + echo \json_encode($responseData, \JSON_THROW_ON_ERROR); exit; } diff --git a/wcfsetup/install/files/lib/system/file/processor/FileProcessor.class.php b/wcfsetup/install/files/lib/system/file/processor/FileProcessor.class.php index c2171d05736..27671470de4 100644 --- a/wcfsetup/install/files/lib/system/file/processor/FileProcessor.class.php +++ b/wcfsetup/install/files/lib/system/file/processor/FileProcessor.class.php @@ -23,7 +23,6 @@ use wcf\system\WCF; use wcf\util\ExifUtil; use wcf\util\FileUtil; -use wcf\util\JSON; use wcf\util\StringUtil; use function wcf\functions\exception\logThrowable; @@ -129,11 +128,11 @@ public function getHtmlElement(IFileProcessor $fileProcessor, array $context): s > HTML, StringUtil::encodeHTML($fileProcessor->getObjectTypeName()), - StringUtil::encodeHTML(JSON::encode($context)), + StringUtil::encodeHTML(\json_encode($context, \JSON_THROW_ON_ERROR)), StringUtil::encodeHTML($allowedFileExtensions), - StringUtil::encodeHTML(JSON::encode($fileProcessor->getResizeConfiguration())), + StringUtil::encodeHTML(\json_encode($fileProcessor->getResizeConfiguration(), \JSON_THROW_ON_ERROR)), $cropperConfiguration === null ? '' - : 'data-cropper-configuration="' . StringUtil::encodeHTML(JSON::encode($cropperConfiguration)) . '"', + : 'data-cropper-configuration="' . StringUtil::encodeHTML(\json_encode($cropperConfiguration, \JSON_THROW_ON_ERROR)) . '"', $maximumCount, $maximumSize, ); @@ -375,7 +374,7 @@ public function hasReachedUploadLimit(IFileProcessor $fileProcessor, array $cont $statement = WCF::getDB()->prepare($sql); $statement->execute([ $this->getObjectType($fileProcessor->getObjectTypeName())->objectTypeID, - JSON::encode($context), + \json_encode($context, \JSON_THROW_ON_ERROR), ]); $numberOfTemporaryFiles = $statement->fetchSingleColumn(); if ($existingFiles + $numberOfTemporaryFiles >= $maximumCount) { diff --git a/wcfsetup/install/files/lib/system/form/option/TSelectOptionsFormOption.class.php b/wcfsetup/install/files/lib/system/form/option/TSelectOptionsFormOption.class.php index 5e0acc9a18b..9f9a478498d 100644 --- a/wcfsetup/install/files/lib/system/form/option/TSelectOptionsFormOption.class.php +++ b/wcfsetup/install/files/lib/system/form/option/TSelectOptionsFormOption.class.php @@ -4,7 +4,6 @@ use wcf\system\form\builder\field\ISelectionFormField; use wcf\system\WCF; -use wcf\util\JSON; /** * Provides helper methods for form options that use select options. @@ -26,7 +25,7 @@ protected function setSelectOptions(ISelectionFormField $formField, array $confi } $selectOptions = []; - foreach (JSON::decode($configuration['selectOptions']) as $selectOption) { + foreach (\json_decode($configuration['selectOptions'], true, flags: \JSON_THROW_ON_ERROR) as $selectOption) { if (isset($selectOption['value'][0])) { $value = $selectOption['value'][0]; } else if (isset($selectOption['value'][WCF::getLanguage()->languageID])) { diff --git a/wcfsetup/install/files/lib/system/form/option/formatter/MultipleSelectionFormatter.class.php b/wcfsetup/install/files/lib/system/form/option/formatter/MultipleSelectionFormatter.class.php index 3fe220f36f3..d9b4d91500d 100644 --- a/wcfsetup/install/files/lib/system/form/option/formatter/MultipleSelectionFormatter.class.php +++ b/wcfsetup/install/files/lib/system/form/option/formatter/MultipleSelectionFormatter.class.php @@ -2,7 +2,7 @@ namespace wcf\system\form\option\formatter; -use wcf\util\JSON; + use wcf\util\StringUtil; /** @@ -23,7 +23,7 @@ public function format(string $value, int $languageID, array $configuration): st }; $keys = \explode(",", $value); - $selectOptions = JSON::decode($configuration['selectOptions']); + $selectOptions = \json_decode($configuration['selectOptions'], true, flags: \JSON_THROW_ON_ERROR); $html = ''; foreach ($keys as $key) { diff --git a/wcfsetup/install/files/lib/system/form/option/formatter/SelectFormatter.class.php b/wcfsetup/install/files/lib/system/form/option/formatter/SelectFormatter.class.php index 989d72e0028..5145a777b16 100644 --- a/wcfsetup/install/files/lib/system/form/option/formatter/SelectFormatter.class.php +++ b/wcfsetup/install/files/lib/system/form/option/formatter/SelectFormatter.class.php @@ -2,7 +2,7 @@ namespace wcf\system\form\option\formatter; -use wcf\util\JSON; + use wcf\util\StringUtil; /** @@ -20,7 +20,7 @@ public function __construct(private readonly bool $encode = true) {} #[\Override] public function format(string $value, int $languageID, array $configuration): string { - foreach (JSON::decode($configuration['selectOptions']) as $selectOption) { + foreach (\json_decode($configuration['selectOptions'], true, flags: \JSON_THROW_ON_ERROR) as $selectOption) { if ($selectOption['key'] == $value) { if (isset($selectOption['value'][0])) { $value = $selectOption['value'][0]; diff --git a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeImg.class.php b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeImg.class.php index 593b0b1be42..7f838740ab2 100644 --- a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeImg.class.php +++ b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeImg.class.php @@ -8,7 +8,6 @@ use wcf\system\bbcode\BBCodeParser; use wcf\system\html\node\AbstractHtmlNodeProcessor; use wcf\util\DOMUtil; -use wcf\util\JSON; use wcf\util\StringUtil; /** @@ -149,7 +148,7 @@ protected function handleAttachment(\DOMElement $element, $class) $newElement = $element->ownerDocument->createElement('woltlab-metacode'); $newElement->setAttribute('data-name', 'attach'); - $newElement->setAttribute('data-attributes', \base64_encode(JSON::encode($attributes))); + $newElement->setAttribute('data-attributes', \base64_encode(\json_encode($attributes, \JSON_THROW_ON_ERROR))); DOMUtil::replaceElement($replaceElement, $newElement, false); } @@ -207,7 +206,7 @@ private function handleMedium(\DOMElement $element): void $newElement = $element->ownerDocument->createElement('woltlab-metacode'); $newElement->setAttribute('data-name', 'wsm'); - $newElement->setAttribute('data-attributes', \base64_encode(JSON::encode($attributes))); + $newElement->setAttribute('data-attributes', \base64_encode(\json_encode($attributes, \JSON_THROW_ON_ERROR))); DOMUtil::replaceElement($replaceElement, $newElement, false); // The media bbcode is a block element that may not be placed inside inline elements. diff --git a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeTextParser.class.php b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeTextParser.class.php index bb82a747c42..631294e1331 100644 --- a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeTextParser.class.php +++ b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeTextParser.class.php @@ -13,7 +13,6 @@ use wcf\system\database\util\PreparedStatementConditionBuilder; use wcf\system\WCF; use wcf\util\FileUtil; -use wcf\util\JSON; use wcf\util\StringUtil; /** @@ -386,7 +385,7 @@ protected function parseMention(\DOMText $text, string $value, array $users, arr if ($pos !== false) { $element = $text->ownerDocument->createElement('woltlab-metacode'); $element->setAttribute('data-name', $bbcodeTagName); - $element->setAttribute('data-attributes', \base64_encode(JSON::encode([$objectID]))); + $element->setAttribute('data-attributes', \base64_encode(\json_encode([$objectID], \JSON_THROW_ON_ERROR))); $element->appendChild($text->ownerDocument->createTextNode($objectTitle)); $marker = $this->addReplacement($text, $element); diff --git a/wcfsetup/install/files/lib/system/html/node/HtmlNodePlainLink.class.php b/wcfsetup/install/files/lib/system/html/node/HtmlNodePlainLink.class.php index 484834d9e92..c3f4dcdc4af 100644 --- a/wcfsetup/install/files/lib/system/html/node/HtmlNodePlainLink.class.php +++ b/wcfsetup/install/files/lib/system/html/node/HtmlNodePlainLink.class.php @@ -7,7 +7,6 @@ use wcf\data\ITitledObject; use wcf\system\Regex; use wcf\util\DOMUtil; -use wcf\util\JSON; /** * Wrapper for links that do not have a dedicated title and are most likely the result of @@ -171,7 +170,7 @@ public function replaceWithBBCode(BBCode $bbcode, $overrideObjectID = null) $metacodeElement->setAttribute('data-name', $bbcode->bbcodeTag); $metacodeElement->setAttribute( 'data-attributes', - \base64_encode(JSON::encode([($overrideObjectID !== null ? $overrideObjectID : $this->objectID)])) + \base64_encode(\json_encode([($overrideObjectID !== null ? $overrideObjectID : $this->objectID)], \JSON_THROW_ON_ERROR)) ); if ($bbcode->isBlockElement) { diff --git a/wcfsetup/install/files/lib/system/importer/AbstractAttachmentImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractAttachmentImporter.class.php index 7311fb78c2b..cea149ac5ae 100644 --- a/wcfsetup/install/files/lib/system/importer/AbstractAttachmentImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/AbstractAttachmentImporter.class.php @@ -6,7 +6,6 @@ use wcf\data\attachment\AttachmentEditor; use wcf\system\exception\SystemException; use wcf\util\FileUtil; -use wcf\util\JSON; /** * Imports attachments. @@ -127,12 +126,12 @@ static function (array $matches) use ($oldID, $newID): string { $base64Decoded = \base64_decode($matches['attributes']); if ($base64Decoded) { try { - $attributes = JSON::decode($base64Decoded); + $attributes = \json_decode($base64Decoded, true, flags: \JSON_THROW_ON_ERROR); if ($attributes[0] == $oldID) { $attributes[0] = $newID; } - $encodedAttributes = \base64_encode(JSON::encode($attributes)); + $encodedAttributes = \base64_encode(\json_encode($attributes, \JSON_THROW_ON_ERROR)); } catch (\Exception $e) { $encodedAttributes = $matches['attributes']; } diff --git a/wcfsetup/install/files/lib/system/interaction/bulk/BulkFormBuilderDialogInteraction.class.php b/wcfsetup/install/files/lib/system/interaction/bulk/BulkFormBuilderDialogInteraction.class.php index caabefafd6c..f65e788610f 100644 --- a/wcfsetup/install/files/lib/system/interaction/bulk/BulkFormBuilderDialogInteraction.class.php +++ b/wcfsetup/install/files/lib/system/interaction/bulk/BulkFormBuilderDialogInteraction.class.php @@ -5,7 +5,7 @@ use wcf\data\DatabaseObject; use wcf\system\request\LinkHandler; use wcf\system\WCF; -use wcf\util\JSON; + use wcf\util\StringUtil; /** @@ -40,7 +40,7 @@ public function render(array $objects): string ); $jsonObjectIDs = StringUtil::encodeHTML( - JSON::encode($objectIDs) + \json_encode($objectIDs, \JSON_THROW_ON_ERROR) ); return <<getControllerLink(ApiAction::class, ['id' => 'rpc']) . $this->endpoint ); $objectIDs = StringUtil::encodeHTML( - JSON::encode( - \array_values(\array_map(fn(DatabaseObject $object) => $object->getObjectID(), $objects)) + \json_encode( + \array_values(\array_map(fn(DatabaseObject $object) => $object->getObjectID(), $objects)), + \JSON_THROW_ON_ERROR ) ); diff --git a/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php b/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php index 9004d25ced1..e014e69c4f5 100644 --- a/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php @@ -41,7 +41,6 @@ use wcf\util\CryptoUtil; use wcf\util\FileUtil; use wcf\util\HeaderUtil; -use wcf\util\JSON; /** * PackageInstallationDispatcher handles the whole installation process. @@ -388,7 +387,7 @@ protected function logInstallationStep(array $node = [], string $log = ''): void $nodeData = \unserialize($node['nodeData']); foreach ($nodeData as $index => $value) { - $logEntry .= "\t" . $index . ': ' . (!\is_object($value) && !\is_array($value) ? $value : JSON::encode($value)) . "\n"; + $logEntry .= "\t" . $index . ': ' . (!\is_object($value) && !\is_array($value) ? $value : \json_encode($value, \JSON_THROW_ON_ERROR)) . "\n"; } } diff --git a/wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php b/wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php index 249805c6623..d8618bb9a6e 100644 --- a/wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php @@ -19,7 +19,6 @@ use wcf\system\package\validation\PackageValidationException; use wcf\system\SingletonFactory; use wcf\system\WCF; -use wcf\util\JSON; use wcf\util\StringUtil; use wcf\util\XML; @@ -151,7 +150,7 @@ private function fetchPurchasedVersions(): void try { $response = $client->send($request); - $reply = JSON::decode((string)$response->getBody()); + $reply = \json_decode((string)$response->getBody(), true, flags: \JSON_THROW_ON_ERROR); if ($reply['status'] == 200) { $this->hasAuthCode = true; @@ -160,7 +159,7 @@ private function fetchPurchasedVersions(): void 'pluginstore' => ($reply['pluginstore'] ?? []), ]; } - } catch (ClientExceptionInterface | SystemException) { + } catch (ClientExceptionInterface | \JsonException) { // ignore } } diff --git a/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php b/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php index c2b44892b16..f9c6afe7233 100644 --- a/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php +++ b/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php @@ -28,7 +28,6 @@ use wcf\system\user\activity\point\UserActivityPointHandler; use wcf\system\user\notification\UserNotificationHandler; use wcf\system\WCF; -use wcf\util\JSON; use wcf\util\StringUtil; /** @@ -89,7 +88,7 @@ public function getReactionsJSVariable() ]; } - return JSON::encode($returnValues); + return \json_encode($returnValues, \JSON_THROW_ON_ERROR); } /** diff --git a/wcfsetup/install/files/lib/system/style/StyleCompiler.class.php b/wcfsetup/install/files/lib/system/style/StyleCompiler.class.php index 351c87ff16e..404019ca568 100644 --- a/wcfsetup/install/files/lib/system/style/StyleCompiler.class.php +++ b/wcfsetup/install/files/lib/system/style/StyleCompiler.class.php @@ -16,7 +16,6 @@ use wcf\command\style\CreateManifest; use wcf\system\WCF; use wcf\util\FileUtil; -use wcf\util\JSON; use wcf\util\StringUtil; use wcf\util\StyleUtil; use wcf\util\Url; @@ -764,7 +763,7 @@ private function writeCss(string $filePrefix, string $css, ?array $preloadManife FileUtil::makeWritable($filePrefix . '-rtl.css'); if ($preloadManifest) { - \file_put_contents($filePrefix . '-preload.json', JSON::encode($preloadManifest)); + \file_put_contents($filePrefix . '-preload.json', \json_encode($preloadManifest, \JSON_THROW_ON_ERROR)); FileUtil::makeWritable($filePrefix . '-preload.json'); } } diff --git a/wcfsetup/install/files/lib/system/style/StyleHandler.class.php b/wcfsetup/install/files/lib/system/style/StyleHandler.class.php index 84de647ae5c..9363dc02656 100644 --- a/wcfsetup/install/files/lib/system/style/StyleHandler.class.php +++ b/wcfsetup/install/files/lib/system/style/StyleHandler.class.php @@ -10,7 +10,6 @@ use wcf\system\request\RequestHandler; use wcf\system\SingletonFactory; use wcf\system\WCF; -use wcf\util\JSON; /** * Handles styles. @@ -287,7 +286,7 @@ public function showColorSchemeSelector(): bool public function getIcons($toJSON = false) { if ($toJSON) { - return JSON::encode([]); + return \json_encode([], \JSON_THROW_ON_ERROR); } return []; diff --git a/wcfsetup/install/files/lib/system/template/plugin/IconFunctionTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/IconFunctionTemplatePlugin.class.php index a544e5916cb..a9bb092de24 100644 --- a/wcfsetup/install/files/lib/system/template/plugin/IconFunctionTemplatePlugin.class.php +++ b/wcfsetup/install/files/lib/system/template/plugin/IconFunctionTemplatePlugin.class.php @@ -7,7 +7,6 @@ use wcf\system\style\FontAwesomeIconBrand; use wcf\system\style\IFontAwesomeIcon; use wcf\system\template\TemplateEngine; -use wcf\util\JSON; /** * Template function plugin that embeds icons into the page. The @@ -67,7 +66,7 @@ public function execute($tagArgs, TemplateEngine $tplObj) $html = $icon->toHtml($size); if ($encodeJson) { - return JSON::encode($html); + return \json_encode($html, \JSON_THROW_ON_ERROR); } return $html; diff --git a/wcfsetup/install/files/lib/system/template/plugin/IconPrefilterTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/IconPrefilterTemplatePlugin.class.php index 67fceda4a15..6395c4fb0e2 100644 --- a/wcfsetup/install/files/lib/system/template/plugin/IconPrefilterTemplatePlugin.class.php +++ b/wcfsetup/install/files/lib/system/template/plugin/IconPrefilterTemplatePlugin.class.php @@ -7,7 +7,6 @@ use wcf\system\style\FontAwesomeIconBrand; use wcf\system\style\IFontAwesomeIcon; use wcf\system\template\TemplateScriptingCompiler; -use wcf\util\JSON; /** * See IconFunctionTemplatePlugin. @@ -41,7 +40,7 @@ function ($match) { $html = $this->getIcon($type, $name)->toHtml($size); if ($encodeJson) { - return JSON::encode($html); + return \json_encode($html, \JSON_THROW_ON_ERROR); } return $html; diff --git a/wcfsetup/install/files/lib/system/template/plugin/JsonModifierTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/JsonModifierTemplatePlugin.class.php index 2194b1d1350..d9053e438a3 100644 --- a/wcfsetup/install/files/lib/system/template/plugin/JsonModifierTemplatePlugin.class.php +++ b/wcfsetup/install/files/lib/system/template/plugin/JsonModifierTemplatePlugin.class.php @@ -3,7 +3,6 @@ namespace wcf\system\template\plugin; use wcf\system\template\TemplateEngine; -use wcf\util\JSON; /** * JSON encodes the given value. @@ -28,6 +27,6 @@ class JsonModifierTemplatePlugin implements IModifierTemplatePlugin */ public function execute($tagArgs, TemplateEngine $tplObj) { - return JSON::encode($tagArgs[0]); + return \json_encode($tagArgs[0], \JSON_THROW_ON_ERROR); } } diff --git a/wcfsetup/install/files/lib/util/ExceptionLogUtil.class.php b/wcfsetup/install/files/lib/util/ExceptionLogUtil.class.php index 0a680eacb19..f5aef43d0bf 100644 --- a/wcfsetup/install/files/lib/util/ExceptionLogUtil.class.php +++ b/wcfsetup/install/files/lib/util/ExceptionLogUtil.class.php @@ -98,7 +98,7 @@ public static function parseException($entry) } try { - $item['stack'] = JSON::decode($item['stack']); + $item['stack'] = \json_decode($item['stack'], true, flags: \JSON_THROW_ON_ERROR); } catch (SystemException $e) { throw new \InvalidArgumentException('The stack trace of the given entry is malformed.', 0, $e); } diff --git a/wcfsetup/install/files/lib/util/UserUtil.class.php b/wcfsetup/install/files/lib/util/UserUtil.class.php index 6fc505dd72e..f6ad7894a67 100644 --- a/wcfsetup/install/files/lib/util/UserUtil.class.php +++ b/wcfsetup/install/files/lib/util/UserUtil.class.php @@ -3,7 +3,6 @@ namespace wcf\util; use wcf\system\email\Mailbox; -use wcf\system\exception\SystemException; use wcf\system\WCF; /** @@ -252,11 +251,12 @@ public static function getRequestURI(): string */ public static function createGuestToken(string $username): string { - return CryptoUtil::createSignedString(JSON::encode( + return CryptoUtil::createSignedString(\json_encode( [ 'username' => $username, 'time' => TIME_NOW, - ] + ], + \JSON_THROW_ON_ERROR )); } @@ -278,8 +278,8 @@ public static function verifyGuestToken(string $token): ?string } try { - $data = JSON::decode($json); - } catch (SystemException $e) { + $data = \json_decode($json, true, flags: \JSON_THROW_ON_ERROR); + } catch (\JsonException) { return null; }