Bladeren bron

Merge pull request #150 from siad007/patch-2

Fixes #144 - Unit test failed: Zend_JsonTest::testDecodingInvalidJsonShouldRaiseAnException
Frank Brückner 12 jaren geleden
bovenliggende
commit
f9c6d8fcf7
3 gewijzigde bestanden met toevoegingen van 9 en 10 verwijderingen
  1. 3 3
      library/Zend/Config/Json.php
  2. 3 1
      library/Zend/Json.php
  3. 3 6
      library/Zend/Serializer/Adapter/Json.php

+ 3 - 3
library/Zend/Config/Json.php

@@ -128,9 +128,9 @@ class Zend_Config_Json extends Zend_Config
         }
 
         // Parse/decode
-        $config = Zend_Json::decode($json);
-
-        if (null === $config) {
+        try {
+            $config = Zend_Json::decode($json);
+        } catch (Zend_Json_Exception $e) {
             // decode failed
             require_once 'Zend/Config/Exception.php';
             throw new Zend_Config_Exception("Error parsing JSON data");

+ 3 - 1
library/Zend/Json.php

@@ -77,7 +77,9 @@ class Zend_Json
 
             // php < 5.3
             if (!function_exists('json_last_error')) {
-                if ($decode === $encodedValue) {
+                if (strtolower($encodedValue) === 'null') {
+                    return null;
+                } elseif ($decode === null) {
                     require_once 'Zend/Json/Exception.php';
                     throw new Zend_Json_Exception('Decoding failed');
                 }

+ 3 - 6
library/Zend/Serializer/Adapter/Json.php

@@ -77,17 +77,14 @@ class Zend_Serializer_Adapter_Json extends Zend_Serializer_Adapter_AdapterAbstra
 
         try {
             $ret = Zend_Json::decode($json, $opts['objectDecodeType']);
+        } catch (Zend_Json_Exception $e) {
+            require_once 'Zend/Serializer/Exception.php';
+            throw new Zend_Serializer_Exception('Invalid json data');
         } catch (Exception $e) {
             require_once 'Zend/Serializer/Exception.php';
             throw new Zend_Serializer_Exception('Unserialization failed by previous error', 0, $e);
         }
 
-        // json_decode returns null for invalid JSON
-        if ($ret === null && $json !== 'null') {
-            require_once 'Zend/Serializer/Exception.php';
-            throw new Zend_Serializer_Exception('Invalid json data');
-        }
-
         return $ret;
     }
 }