Ejemplo n.º 1
0
 /**
  * @group ZF-4054
  */
 public function testEncodeUnicodeStringSolarRegression()
 {
     $value = 'héllö wørłd';
     $expected = 'h\\u00c3\\u00a9ll\\u00c3\\u00b6 w\\u00c3\\u00b8r\\u00c5\\u201ad';
     $this->assertEquals($expected, Json\Encoder::encodeUnicodeString($value));
     $value = "ä";
     $expected = '\\u00e4';
     $this->assertEquals($expected, Json\Encoder::encodeUnicodeString($value));
     $value = "ႠႨ";
     $expected = '\\u10a0\\u10a8';
     $this->assertEquals($expected, Json\Encoder::encodeUnicodeString($value));
 }
Ejemplo n.º 2
0
 /**
  * Discover and replace javascript expressions with temporary placeholders.
  *
  * Check each value to determine if it is a Zend\Json\Expr; if so, replace the value with
  * a magic key and add the javascript expression to the queue.
  *
  * NOTE this method is recursive.
  *
  * NOTE: This method is used internally by the encode method.
  *
  * @see encode
  * @param mixed $value a string - object property to be encoded
  * @param SplQueue $javascriptExpressions
  * @param null|string|int $currentKey
  * @return mixed
  */
 protected static function recursiveJsonExprFinder($value, SplQueue $javascriptExpressions, $currentKey = null)
 {
     if ($value instanceof Expr) {
         // TODO: Optimize with ascii keys, if performance is bad
         $magicKey = "____" . $currentKey . "_" . count($javascriptExpressions);
         $javascriptExpressions->enqueue(['magicKey' => is_int($currentKey) ? $magicKey : Encoder::encodeUnicodeString($magicKey), 'value' => $value]);
         return $magicKey;
     }
     if (is_array($value)) {
         foreach ($value as $k => $v) {
             $value[$k] = static::recursiveJsonExprFinder($value[$k], $javascriptExpressions, $k);
         }
         return $value;
     }
     if (is_object($value)) {
         foreach ($value as $k => $v) {
             $value->{$k} = static::recursiveJsonExprFinder($value->{$k}, $javascriptExpressions, $k);
         }
         return $value;
     }
     return $value;
 }
Ejemplo n.º 3
0
 /**
  * Check & Replace Zend\Json\Expr for tmp ids in the valueToEncode
  *
  * Check if the value is a Zend\Json\Expr, and if replace its value
  * with a magic key and save the javascript expression in an array.
  *
  * NOTE this method is recursive.
  *
  * NOTE: This method is used internally by the encode method.
  *
  * @see encode
  * @param mixed $value a string - object property to be encoded
  * @param array $javascriptExpressions
  * @param null|string|int $currentKey
  * @return mixed
  */
 protected static function _recursiveJsonExprFinder(&$value, array &$javascriptExpressions, $currentKey = null)
 {
     if ($value instanceof Expr) {
         // TODO: Optimize with ascii keys, if performance is bad
         $magicKey = "____" . $currentKey . "_" . count($javascriptExpressions);
         $javascriptExpressions[] = array("magicKey" => is_int($currentKey) ? $magicKey : Encoder::encodeUnicodeString($magicKey), "value" => $value->__toString());
         $value = $magicKey;
     } elseif (is_array($value)) {
         foreach ($value as $k => $v) {
             $value[$k] = static::_recursiveJsonExprFinder($value[$k], $javascriptExpressions, $k);
         }
     } elseif (is_object($value)) {
         foreach ($value as $k => $v) {
             $value->{$k} = static::_recursiveJsonExprFinder($value->{$k}, $javascriptExpressions, $k);
         }
     }
     return $value;
 }
Ejemplo n.º 4
0
    /**
     * @group ZF-4054
     */
    public function testEncodeUnicodeStringSolarRegression()
    {
        $value    = 'héllö wørłd';
        $expected = 'h\u00c3\u00a9ll\u00c3\u00b6 w\u00c3\u00b8r\u00c5\u201ad';
        $this->assertEquals($expected, Json\Encoder::encodeUnicodeString($value));

        $value    = "\xC3\xA4";
        $expected = '\u00e4';
        $this->assertEquals($expected, Json\Encoder::encodeUnicodeString($value));

        $value    = "\xE1\x82\xA0\xE1\x82\xA8";
        $expected = '\u10a0\u10a8';
        $this->assertEquals($expected, Json\Encoder::encodeUnicodeString($value));
    }