Sfoglia il codice sorgente

ZF-8663
- Fixed Zend_Json_Encoder (internal) to encode solidus in string values

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@20070 44c647ce-9c0f-0410-b52a-842ac1e357ba

ralph 16 anni fa
parent
commit
84bdeae7ae
2 ha cambiato i file con 29 aggiunte e 2 eliminazioni
  1. 2 2
      library/Zend/Json/Encoder.php
  2. 27 0
      tests/Zend/JsonTest.php

+ 2 - 2
library/Zend/Json/Encoder.php

@@ -252,8 +252,8 @@ class Zend_Json_Encoder
     {
         // Escape these characters with a backslash:
         // " \ / \n \r \t \b \f
-        $search  = array('\\', "\n", "\t", "\r", "\b", "\f", '"');
-        $replace = array('\\\\', '\\n', '\\t', '\\r', '\\b', '\\f', '\"');
+        $search  = array('\\', "\n", "\t", "\r", "\b", "\f", '"', '/');
+        $replace = array('\\\\', '\\n', '\\t', '\\r', '\\b', '\\f', '\"', '\\/');
         $string  = str_replace($search, $replace, $string);
 
         // Escape certain ASCII characters:

+ 27 - 0
tests/Zend/JsonTest.php

@@ -720,6 +720,33 @@ class Zend_JsonTest extends PHPUnit_Framework_TestCase
     {
         $this->markTestIncomplete('Test is not yet finished.');
     }
+    
+    /**
+     * @group ZF-8663
+     */
+    public function testNativeJsonEncoderWillProperlyEncodeSolidusInStringValues()
+    {
+        $source = "</foo><foo>bar</foo>";
+        $target = '"<\\/foo><foo>bar<\\/foo>"';
+        
+        // first test ext/json
+        Zend_Json::$useBuiltinEncoderDecoder = false;
+        $this->assertEquals($target, Zend_Json::encode($source));
+    }
+    
+    /**
+     * @group ZF-8663
+     */
+    public function testBuiltinJsonEncoderWillProperlyEncodeSolidusInStringValues()
+    {
+        $source = "</foo><foo>bar</foo>";
+        $target = '"<\\/foo><foo>bar<\\/foo>"';
+        
+        // first test ext/json
+        Zend_Json::$useBuiltinEncoderDecoder = true;
+        $this->assertEquals($target, Zend_Json::encode($source));
+    }
+    
 }
 
 /**