Преглед на файлове

Switch to PHP native JsonException type

El RIDO преди 1 седмица
родител
ревизия
310c2efbab

+ 1 - 0
CHANGELOG.md

@@ -2,6 +2,7 @@
 
 ## 2.0.6 (not yet released)
 * CHANGED: Upgrading libraries to: DOMpurify 3.4.12
+* CHANGED: Switch to PHP native JsonException type
 * FIXED: Gracefully handle YOURLS replies with a 200 status code but no shorturl, instead of raising a TypeError
 * FIXED: Return "Invalid data." instead of HTTP 500 on malformed v2 JSON payloads (#1883)
 

+ 15 - 32
composer.lock

@@ -396,20 +396,19 @@
         },
         {
             "name": "nikic/php-parser",
-            "version": "v5.7.0",
+            "version": "v5.8.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/nikic/PHP-Parser.git",
-                "reference": "dca41cd15c2ac9d055ad70dbfd011130757d1f82"
+                "reference": "044a6a392ff8ad0d61f14370a5fbbd0a0107152f"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/dca41cd15c2ac9d055ad70dbfd011130757d1f82",
-                "reference": "dca41cd15c2ac9d055ad70dbfd011130757d1f82",
+                "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/044a6a392ff8ad0d61f14370a5fbbd0a0107152f",
+                "reference": "044a6a392ff8ad0d61f14370a5fbbd0a0107152f",
                 "shasum": ""
             },
             "require": {
-                "ext-ctype": "*",
                 "ext-json": "*",
                 "ext-tokenizer": "*",
                 "php": ">=7.4"
@@ -448,9 +447,9 @@
             ],
             "support": {
                 "issues": "https://github.com/nikic/PHP-Parser/issues",
-                "source": "https://github.com/nikic/PHP-Parser/tree/v5.7.0"
+                "source": "https://github.com/nikic/PHP-Parser/tree/v5.8.0"
             },
-            "time": "2025-12-06T11:56:16+00:00"
+            "time": "2026-07-04T14:30:18+00:00"
         },
         {
             "name": "phar-io/manifest",
@@ -891,25 +890,25 @@
         },
         {
             "name": "phpunit/phpunit",
-            "version": "9.6.34",
+            "version": "9.6.35",
             "source": {
                 "type": "git",
                 "url": "https://github.com/sebastianbergmann/phpunit.git",
-                "reference": "b36f02317466907a230d3aa1d34467041271ef4a"
+                "reference": "0edba2f3a0c48df3553cb9b640810b30df60302b"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/b36f02317466907a230d3aa1d34467041271ef4a",
-                "reference": "b36f02317466907a230d3aa1d34467041271ef4a",
+                "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/0edba2f3a0c48df3553cb9b640810b30df60302b",
+                "reference": "0edba2f3a0c48df3553cb9b640810b30df60302b",
                 "shasum": ""
             },
             "require": {
                 "doctrine/instantiator": "^1.5.0 || ^2",
                 "ext-dom": "*",
+                "ext-filter": "*",
                 "ext-json": "*",
                 "ext-libxml": "*",
                 "ext-mbstring": "*",
-                "ext-xml": "*",
                 "ext-xmlwriter": "*",
                 "myclabs/deep-copy": "^1.13.4",
                 "phar-io/manifest": "^2.0.4",
@@ -974,31 +973,15 @@
             "support": {
                 "issues": "https://github.com/sebastianbergmann/phpunit/issues",
                 "security": "https://github.com/sebastianbergmann/phpunit/security/policy",
-                "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.34"
+                "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.35"
             },
             "funding": [
                 {
-                    "url": "https://phpunit.de/sponsors.html",
-                    "type": "custom"
-                },
-                {
-                    "url": "https://github.com/sebastianbergmann",
-                    "type": "github"
-                },
-                {
-                    "url": "https://liberapay.com/sebastianbergmann",
-                    "type": "liberapay"
-                },
-                {
-                    "url": "https://thanks.dev/u/gh/sebastianbergmann",
-                    "type": "thanks_dev"
-                },
-                {
-                    "url": "https://tidelift.com/funding/github/packagist/phpunit/phpunit",
-                    "type": "tidelift"
+                    "url": "https://phpunit.de/sponsoring.html",
+                    "type": "other"
                 }
             ],
-            "time": "2026-01-27T05:45:00+00:00"
+            "time": "2026-07-06T14:48:07+00:00"
         },
         {
             "name": "sebastian/cli-parser",

+ 0 - 1
lib/Controller.php

@@ -12,7 +12,6 @@
 namespace PrivateBin;
 
 use Exception;
-use PrivateBin\Exception\JsonException;
 use PrivateBin\Exception\TranslatedException;
 use PrivateBin\Persistence\ServerSalt;
 use PrivateBin\Persistence\TrafficLimiter;

+ 1 - 1
lib/Data/Database.php

@@ -12,10 +12,10 @@
 namespace PrivateBin\Data;
 
 use Exception;
+use JsonException;
 use PDO;
 use PDOException;
 use PrivateBin\Controller;
-use PrivateBin\Exception\JsonException;
 use PrivateBin\Json;
 
 /**

+ 1 - 1
lib/Data/Filesystem.php

@@ -13,7 +13,7 @@ namespace PrivateBin\Data;
 
 use DirectoryIterator;
 use GlobIterator;
-use PrivateBin\Exception\JsonException;
+use JsonException;
 use PrivateBin\Json;
 
 /**

+ 1 - 1
lib/Data/GoogleCloudStorage.php

@@ -15,7 +15,7 @@ use Exception;
 use Google\Cloud\Core\Exception\NotFoundException;
 use Google\Cloud\Storage\Bucket;
 use Google\Cloud\Storage\StorageClient;
-use PrivateBin\Exception\JsonException;
+use JsonException;
 use PrivateBin\Json;
 
 class GoogleCloudStorage extends AbstractData

+ 1 - 1
lib/Data/S3Storage.php

@@ -37,7 +37,7 @@ namespace PrivateBin\Data;
 
 use Aws\S3\Exception\S3Exception;
 use Aws\S3\S3Client;
-use PrivateBin\Exception\JsonException;
+use JsonException;
 use PrivateBin\Json;
 
 class S3Storage extends AbstractData

+ 0 - 38
lib/Exception/JsonException.php

@@ -1,38 +0,0 @@
-<?php declare(strict_types=1);
-/**
- * PrivateBin
- *
- * a zero-knowledge paste bin
- *
- * @link      https://github.com/PrivateBin/PrivateBin
- * @copyright 2012 Sébastien SAUVAGE (sebsauvage.net)
- * @license   https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
- */
-
-namespace PrivateBin\Exception;
-
-use Exception;
-
-/**
- * JsonException
- *
- * An Exception representing JSON en- or decoding errors.
- */
-class JsonException extends Exception
-{
-    /**
-     * Exception constructor with mandatory JSON error code.
-     *
-     * @access public
-     * @param  int $code
-     */
-    public function __construct(int $code)
-    {
-        $message = 'A JSON error occurred';
-        if (function_exists('json_last_error_msg')) {
-            $message .= ': ' . json_last_error_msg();
-        }
-        $message .= ' (' . $code . ')';
-        parent::__construct($message, 90);
-    }
-}

+ 2 - 24
lib/Json.php

@@ -11,8 +11,6 @@
 
 namespace PrivateBin;
 
-use PrivateBin\Exception\JsonException;
-
 /**
  * Json
  *
@@ -31,9 +29,7 @@ class Json
      */
     public static function encode(&$input)
     {
-        $jsonString = json_encode($input);
-        self::_detectError();
-        return $jsonString;
+        return json_encode($input, JSON_THROW_ON_ERROR);
     }
 
     /**
@@ -47,24 +43,6 @@ class Json
      */
     public static function decode(&$input)
     {
-        $output = json_decode($input, true);
-        self::_detectError();
-        return $output;
-    }
-
-    /**
-     * Detects JSON errors and raises an exception if one is found
-     *
-     * @access private
-     * @static
-     * @throws JsonException
-     * @return void
-     */
-    private static function _detectError()
-    {
-        $errorCode = json_last_error();
-        if ($errorCode !== JSON_ERROR_NONE) {
-            throw new JsonException($errorCode);
-        }
+        return json_decode($input, true, 10, JSON_THROW_ON_ERROR);
     }
 }

+ 1 - 1
lib/Proxy/AbstractProxy.php

@@ -11,8 +11,8 @@
 
 namespace PrivateBin\Proxy;
 
+use JsonException;
 use PrivateBin\Configuration;
-use PrivateBin\Exception\JsonException;
 use PrivateBin\Json;
 
 /**

+ 1 - 1
lib/Proxy/ShlinkProxy.php

@@ -11,8 +11,8 @@
 
 namespace PrivateBin\Proxy;
 
+use JsonException;
 use PrivateBin\Configuration;
-use PrivateBin\Exception\JsonException;
 use PrivateBin\Json;
 
 /**

+ 1 - 1
lib/Request.php

@@ -11,7 +11,7 @@
 
 namespace PrivateBin;
 
-use PrivateBin\Exception\JsonException;
+use JsonException;
 use PrivateBin\Model\Paste;
 
 /**

+ 0 - 1
vendor/composer/autoload_classmap.php

@@ -74,7 +74,6 @@ return array(
     'PrivateBin\\Data\\Filesystem' => $baseDir . '/lib/Data/Filesystem.php',
     'PrivateBin\\Data\\GoogleCloudStorage' => $baseDir . '/lib/Data/GoogleCloudStorage.php',
     'PrivateBin\\Data\\S3Storage' => $baseDir . '/lib/Data/S3Storage.php',
-    'PrivateBin\\Exception\\JsonException' => $baseDir . '/lib/Exception/JsonException.php',
     'PrivateBin\\Exception\\TranslatedException' => $baseDir . '/lib/Exception/TranslatedException.php',
     'PrivateBin\\Filter' => $baseDir . '/lib/Filter.php',
     'PrivateBin\\FormatV2' => $baseDir . '/lib/FormatV2.php',

+ 0 - 1
vendor/composer/autoload_static.php

@@ -122,7 +122,6 @@ class ComposerStaticInitDontChange
         'PrivateBin\\Data\\Filesystem' => __DIR__ . '/../..' . '/lib/Data/Filesystem.php',
         'PrivateBin\\Data\\GoogleCloudStorage' => __DIR__ . '/../..' . '/lib/Data/GoogleCloudStorage.php',
         'PrivateBin\\Data\\S3Storage' => __DIR__ . '/../..' . '/lib/Data/S3Storage.php',
-        'PrivateBin\\Exception\\JsonException' => __DIR__ . '/../..' . '/lib/Exception/JsonException.php',
         'PrivateBin\\Exception\\TranslatedException' => __DIR__ . '/../..' . '/lib/Exception/TranslatedException.php',
         'PrivateBin\\Filter' => __DIR__ . '/../..' . '/lib/Filter.php',
         'PrivateBin\\FormatV2' => __DIR__ . '/../..' . '/lib/FormatV2.php',

+ 2 - 2
vendor/composer/installed.php

@@ -3,7 +3,7 @@
         'name' => 'privatebin/privatebin',
         'pretty_version' => 'dev-master',
         'version' => 'dev-master',
-        'reference' => '67baf8cca4b7aa1bc57e631b47ab561695c8ce2b',
+        'reference' => '8a77305838325d7be15b9a96e43415a6d2796489',
         'type' => 'project',
         'install_path' => __DIR__ . '/../../',
         'aliases' => array(),
@@ -31,7 +31,7 @@
         'privatebin/privatebin' => array(
             'pretty_version' => 'dev-master',
             'version' => 'dev-master',
-            'reference' => '67baf8cca4b7aa1bc57e631b47ab561695c8ce2b',
+            'reference' => '8a77305838325d7be15b9a96e43415a6d2796489',
             'type' => 'project',
             'install_path' => __DIR__ . '/../../',
             'aliases' => array(),