From b9de474ccec42d3d04f7bb5ad80040f083596ae5 Mon Sep 17 00:00:00 2001 From: Eugene Kuzminov Date: Thu, 17 Oct 2013 15:24:52 +0300 Subject: [PATCH 1/2] debug panel : change json_encode/decode to serialise/unserialise to prevent non-UTF characters error --- framework/yii/debug/LogTarget.php | 6 +++--- framework/yii/debug/controllers/DefaultController.php | 4 ++-- framework/yii/debug/panels/RequestPanel.php | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/framework/yii/debug/LogTarget.php b/framework/yii/debug/LogTarget.php index b415b50..33c81eb 100644 --- a/framework/yii/debug/LogTarget.php +++ b/framework/yii/debug/LogTarget.php @@ -49,7 +49,7 @@ class LogTarget extends Target if (!is_file($indexFile)) { $manifest = array(); } else { - $manifest = json_decode(file_get_contents($indexFile), true); + $manifest = unserialize(file_get_contents($indexFile)); } $request = Yii::$app->getRequest(); $manifest[$this->tag] = $summary = array( @@ -68,8 +68,8 @@ class LogTarget extends Target $data[$id] = $panel->save(); } $data['summary'] = $summary; - file_put_contents($dataFile, json_encode($data)); - file_put_contents($indexFile, json_encode($manifest)); + file_put_contents($dataFile, serialize($data)); + file_put_contents($indexFile, serialize($manifest)); } /** diff --git a/framework/yii/debug/controllers/DefaultController.php b/framework/yii/debug/controllers/DefaultController.php index dd01412..b00881b 100644 --- a/framework/yii/debug/controllers/DefaultController.php +++ b/framework/yii/debug/controllers/DefaultController.php @@ -76,7 +76,7 @@ class DefaultController extends Controller if ($this->_manifest === null) { $indexFile = $this->module->dataPath . '/index.json'; if (is_file($indexFile)) { - $this->_manifest = array_reverse(json_decode(file_get_contents($indexFile), true), true); + $this->_manifest = array_reverse(unserialize(file_get_contents($indexFile)), true); } else { $this->_manifest = array(); } @@ -89,7 +89,7 @@ class DefaultController extends Controller $manifest = $this->getManifest(); if (isset($manifest[$tag])) { $dataFile = $this->module->dataPath . "/$tag.json"; - $data = json_decode(file_get_contents($dataFile), true); + $data = unserialize(file_get_contents($dataFile)); foreach ($this->module->panels as $id => $panel) { if (isset($data[$id])) { $panel->tag = $tag; diff --git a/framework/yii/debug/panels/RequestPanel.php b/framework/yii/debug/panels/RequestPanel.php index 6aa4bf8..58256e4 100644 --- a/framework/yii/debug/panels/RequestPanel.php +++ b/framework/yii/debug/panels/RequestPanel.php @@ -151,7 +151,7 @@ EOD; } $rows = array(); foreach ($values as $name => $value) { - $rows[] = '' . Html::encode($name) . '' . Html::encode(var_export($value, true)) . ''; + $rows[] = '' . Html::encode($name) . '' . htmlspecialchars(var_export($value, true), ENT_QUOTES|ENT_SUBSTITUTE, \Yii::$app->charset, TRUE) . ''; } $rows = implode("\n", $rows); return << Date: Thu, 17 Oct 2013 16:37:31 +0300 Subject: [PATCH 2/2] debug panel : changed .json to .php --- framework/yii/debug/LogTarget.php | 6 +++--- framework/yii/debug/controllers/DefaultController.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/framework/yii/debug/LogTarget.php b/framework/yii/debug/LogTarget.php index 33c81eb..31bca6e 100644 --- a/framework/yii/debug/LogTarget.php +++ b/framework/yii/debug/LogTarget.php @@ -45,7 +45,7 @@ class LogTarget extends Target if (!is_dir($path)) { mkdir($path); } - $indexFile = "$path/index.json"; + $indexFile = "$path/index.php"; if (!is_file($indexFile)) { $manifest = array(); } else { @@ -62,7 +62,7 @@ class LogTarget extends Target ); $this->gc($manifest); - $dataFile = "$path/{$this->tag}.json"; + $dataFile = "$path/{$this->tag}.php"; $data = array(); foreach ($this->module->panels as $id => $panel) { $data[$id] = $panel->save(); @@ -93,7 +93,7 @@ class LogTarget extends Target if (count($manifest) > $this->module->historySize + 10) { $n = count($manifest) - $this->module->historySize; foreach (array_keys($manifest) as $tag) { - $file = $this->module->dataPath . "/$tag.json"; + $file = $this->module->dataPath . "/$tag.php"; @unlink($file); unset($manifest[$tag]); if (--$n <= 0) { diff --git a/framework/yii/debug/controllers/DefaultController.php b/framework/yii/debug/controllers/DefaultController.php index b00881b..2026dc7 100644 --- a/framework/yii/debug/controllers/DefaultController.php +++ b/framework/yii/debug/controllers/DefaultController.php @@ -74,7 +74,7 @@ class DefaultController extends Controller protected function getManifest() { if ($this->_manifest === null) { - $indexFile = $this->module->dataPath . '/index.json'; + $indexFile = $this->module->dataPath . '/index.php'; if (is_file($indexFile)) { $this->_manifest = array_reverse(unserialize(file_get_contents($indexFile)), true); } else { @@ -88,7 +88,7 @@ class DefaultController extends Controller { $manifest = $this->getManifest(); if (isset($manifest[$tag])) { - $dataFile = $this->module->dataPath . "/$tag.json"; + $dataFile = $this->module->dataPath . "/$tag.php"; $data = unserialize(file_get_contents($dataFile)); foreach ($this->module->panels as $id => $panel) { if (isset($data[$id])) {