Commit 48ec791e by Alexander Makarov

Fixes #5587: `json_encode` is now used with `JSON_UNESCAPED_SLASHES |…

Fixes #5587: `json_encode` is now used with `JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE` where it makes sense, also it is now default for `Json::encode()`
parent 6a794f6b
...@@ -518,7 +518,7 @@ class StatusValidator extends Validator ...@@ -518,7 +518,7 @@ class StatusValidator extends Validator
public function clientValidateAttribute($model, $attribute, $view) public function clientValidateAttribute($model, $attribute, $view)
{ {
$statuses = json_encode(Status::find()->select('id')->asArray()->column()); $statuses = json_encode(Status::find()->select('id')->asArray()->column());
$message = json_encode($this->message); $message = json_encode($this->message, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
return <<<JS return <<<JS
if (!$.inArray(value, $statuses)) { if (!$.inArray(value, $statuses)) {
messages.push($message); messages.push($message);
......
...@@ -231,7 +231,7 @@ EOD; ...@@ -231,7 +231,7 @@ EOD;
*/ */
public function getKeywordsArrayJson() public function getKeywordsArrayJson()
{ {
return json_encode(explode(',', $this->keywords)); return json_encode(explode(',', $this->keywords), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
} }
/** /**
......
...@@ -8,6 +8,8 @@ Yii Framework 2 Change Log ...@@ -8,6 +8,8 @@ Yii Framework 2 Change Log
- Bug #5584: `yii\rbac\DbRbacManager` should not delete items when deleting a rule on a database not supporting cascade update (mdmunir) - Bug #5584: `yii\rbac\DbRbacManager` should not delete items when deleting a rule on a database not supporting cascade update (mdmunir)
- Bug #5601: Simple conditions in Query::where() and ActiveQuery::where() did not allow `yii\db\Expression` to be used as the value (cebe, stevekr) - Bug #5601: Simple conditions in Query::where() and ActiveQuery::where() did not allow `yii\db\Expression` to be used as the value (cebe, stevekr)
- Bug: Gii console command help information does not contain global options (qiangxue) - Bug: Gii console command help information does not contain global options (qiangxue)
- Enh #5587: `json_encode` is now used with `JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE` where it makes sense, also
it is now default for `Json::encode()` (samdark)
- Enh #5600: Allow configuring debug panels in `yii\debug\Module::panels` as panel class name strings (qiangxue) - Enh #5600: Allow configuring debug panels in `yii\debug\Module::panels` as panel class name strings (qiangxue)
- Enh #5613: Added `--overwrite` option to Gii console command to support overwriting all files (motin, qiangxue) - Enh #5613: Added `--overwrite` option to Gii console command to support overwriting all files (motin, qiangxue)
- Enh #5646: Call `yii\base\ErrorHandler::unregister()` instead of `restore_*_handlers` directly (aivus) - Enh #5646: Call `yii\base\ErrorHandler::unregister()` instead of `restore_*_handlers` directly (aivus)
......
...@@ -127,7 +127,7 @@ class CaptchaAction extends Action ...@@ -127,7 +127,7 @@ class CaptchaAction extends Action
// we add a random 'v' parameter so that FireFox can refresh the image // we add a random 'v' parameter so that FireFox can refresh the image
// when src attribute of image tag is changed // when src attribute of image tag is changed
'url' => Url::to([$this->id, 'v' => uniqid()]), 'url' => Url::to([$this->id, 'v' => uniqid()]),
]); ], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
} else { } else {
$this->setHttpHeaders(); $this->setHttpHeaders();
Yii::$app->response->format = Response::FORMAT_RAW; Yii::$app->response->format = Response::FORMAT_RAW;
......
...@@ -103,6 +103,6 @@ class CaptchaValidator extends Validator ...@@ -103,6 +103,6 @@ class CaptchaValidator extends Validator
ValidationAsset::register($view); ValidationAsset::register($view);
return 'yii.validation.captcha(value, messages, ' . json_encode($options) . ');'; return 'yii.validation.captcha(value, messages, ' . json_encode($options, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ');';
} }
} }
...@@ -84,7 +84,7 @@ class CheckboxColumn extends Column ...@@ -84,7 +84,7 @@ class CheckboxColumn extends Column
'name' => $this->name, 'name' => $this->name,
'multiple' => $this->multiple, 'multiple' => $this->multiple,
'checkAll' => $name, 'checkAll' => $name,
]); ], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
$this->grid->getView()->registerJs("jQuery('#$id').yiiGridView('setSelectionColumn', $options);"); $this->grid->getView()->registerJs("jQuery('#$id').yiiGridView('setSelectionColumn', $options);");
if ($this->header !== null || !$this->multiple) { if ($this->header !== null || !$this->multiple) {
...@@ -104,7 +104,7 @@ class CheckboxColumn extends Column ...@@ -104,7 +104,7 @@ class CheckboxColumn extends Column
} else { } else {
$options = $this->checkboxOptions; $options = $this->checkboxOptions;
if (!isset($options['value'])) { if (!isset($options['value'])) {
$options['value'] = is_array($key) ? json_encode($key) : $key; $options['value'] = is_array($key) ? json_encode($key, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) : $key;
} }
} }
......
...@@ -28,10 +28,10 @@ class BaseJson ...@@ -28,10 +28,10 @@ class BaseJson
* represented in terms of a [[JsExpression]] object. * represented in terms of a [[JsExpression]] object.
* @param mixed $value the data to be encoded * @param mixed $value the data to be encoded
* @param integer $options the encoding options. For more details please refer to * @param integer $options the encoding options. For more details please refer to
* <http://www.php.net/manual/en/function.json-encode.php>. * <http://www.php.net/manual/en/function.json-encode.php>. Default is `JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE`.
* @return string the encoding result * @return string the encoding result
*/ */
public static function encode($value, $options = 0) public static function encode($value, $options = 320)
{ {
$expressions = []; $expressions = [];
$value = static::processData($value, $expressions, uniqid()); $value = static::processData($value, $expressions, uniqid());
......
...@@ -87,6 +87,6 @@ class BooleanValidator extends Validator ...@@ -87,6 +87,6 @@ class BooleanValidator extends Validator
ValidationAsset::register($view); ValidationAsset::register($view);
return 'yii.validation.boolean(value, messages, ' . json_encode($options) . ');'; return 'yii.validation.boolean(value, messages, ' . json_encode($options, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ');';
} }
} }
...@@ -229,6 +229,6 @@ class CompareValidator extends Validator ...@@ -229,6 +229,6 @@ class CompareValidator extends Validator
ValidationAsset::register($view); ValidationAsset::register($view);
return 'yii.validation.compare(value, messages, ' . json_encode($options) . ');'; return 'yii.validation.compare(value, messages, ' . json_encode($options, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ');';
} }
} }
...@@ -338,7 +338,7 @@ class FileValidator extends Validator ...@@ -338,7 +338,7 @@ class FileValidator extends Validator
{ {
ValidationAsset::register($view); ValidationAsset::register($view);
$options = $this->getClientOptions($object, $attribute); $options = $this->getClientOptions($object, $attribute);
return 'yii.validation.file(attribute, messages, ' . json_encode($options) . ');'; return 'yii.validation.file(attribute, messages, ' . json_encode($options, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ');';
} }
/** /**
......
...@@ -166,7 +166,7 @@ class ImageValidator extends FileValidator ...@@ -166,7 +166,7 @@ class ImageValidator extends FileValidator
{ {
ValidationAsset::register($view); ValidationAsset::register($view);
$options = $this->getClientOptions($object, $attribute); $options = $this->getClientOptions($object, $attribute);
return 'yii.validation.image(attribute, messages, ' . json_encode($options) . ', deferred);'; return 'yii.validation.image(attribute, messages, ' . json_encode($options, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ', deferred);';
} }
/** /**
......
...@@ -101,6 +101,6 @@ class RangeValidator extends Validator ...@@ -101,6 +101,6 @@ class RangeValidator extends Validator
ValidationAsset::register($view); ValidationAsset::register($view);
return 'yii.validation.range(value, messages, ' . json_encode($options) . ');'; return 'yii.validation.range(value, messages, ' . json_encode($options, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ');';
} }
} }
...@@ -107,6 +107,6 @@ class RequiredValidator extends Validator ...@@ -107,6 +107,6 @@ class RequiredValidator extends Validator
ValidationAsset::register($view); ValidationAsset::register($view);
return 'yii.validation.required(value, messages, ' . json_encode($options) . ');'; return 'yii.validation.required(value, messages, ' . json_encode($options, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ');';
} }
} }
...@@ -183,6 +183,6 @@ class StringValidator extends Validator ...@@ -183,6 +183,6 @@ class StringValidator extends Validator
ValidationAsset::register($view); ValidationAsset::register($view);
return 'yii.validation.string(value, messages, ' . json_encode($options) . ');'; return 'yii.validation.string(value, messages, ' . json_encode($options, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ');';
} }
} }
...@@ -538,7 +538,7 @@ class User extends Component ...@@ -538,7 +538,7 @@ class User extends Component
$identity->getId(), $identity->getId(),
$identity->getAuthKey(), $identity->getAuthKey(),
$duration, $duration,
]); ], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
$cookie->expire = time() + $duration; $cookie->expire = time() + $duration;
Yii::$app->getResponse()->getCookies()->add($cookie); Yii::$app->getResponse()->getCookies()->add($cookie);
} }
......
...@@ -101,7 +101,7 @@ class ListView extends BaseListView ...@@ -101,7 +101,7 @@ class ListView extends BaseListView
$options = $this->itemOptions; $options = $this->itemOptions;
$tag = ArrayHelper::remove($options, 'tag', 'div'); $tag = ArrayHelper::remove($options, 'tag', 'div');
if ($tag !== false) { if ($tag !== false) {
$options['data-key'] = is_array($key) ? json_encode($key) : (string) $key; $options['data-key'] = is_array($key) ? json_encode($key, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) : (string) $key;
return Html::tag($tag, $content, $options); return Html::tag($tag, $content, $options);
} else { } else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment