Commit f93054a4 by Carsten Brandt

fixed possible problem with realpath and false value

realpath(false) = current working directory. This can cause problems with getAlias() which returns false. see yiisoft/yii#3113
parent 208d5eac
...@@ -233,8 +233,9 @@ class FixtureController extends \yii\console\controllers\FixtureController ...@@ -233,8 +233,9 @@ class FixtureController extends \yii\console\controllers\FixtureController
} }
$content = $this->exportFixtures($fixtures); $content = $this->exportFixtures($fixtures);
file_put_contents($fixturePath . '/' . $fixtureFileName, $content); $filePath = realpath($fixturePath . '/' . $fixtureFileName);
$this->stdout("Fixture file was generated under: " . realpath($fixturePath . "/" . $fixtureFileName) . "\n", Console::FG_GREEN); file_put_contents($filePath, $content);
$this->stdout("Fixture file was generated under: $filePath\n", Console::FG_GREEN);
} }
} }
...@@ -356,9 +357,9 @@ class FixtureController extends \yii\console\controllers\FixtureController ...@@ -356,9 +357,9 @@ class FixtureController extends \yii\console\controllers\FixtureController
public function confirmGeneration($files) public function confirmGeneration($files)
{ {
$this->stdout("Fixtures will be generated under the path: \n", Console::FG_YELLOW); $this->stdout("Fixtures will be generated under the path: \n", Console::FG_YELLOW);
$this->stdout(realpath(Yii::getAlias($this->fixturePath, false)) . "\n\n", Console::FG_GREEN); $this->stdout(realpath(Yii::getAlias($this->fixturePath)) . "\n\n", Console::FG_GREEN);
$this->stdout("Templates will be taken from path: \n", Console::FG_YELLOW); $this->stdout("Templates will be taken from path: \n", Console::FG_YELLOW);
$this->stdout(realpath(Yii::getAlias($this->templatePath, false)) . "\n\n", Console::FG_GREEN); $this->stdout(realpath(Yii::getAlias($this->templatePath)) . "\n\n", Console::FG_GREEN);
foreach ($files as $index => $fileName) { foreach ($files as $index => $fileName) {
$this->stdout(" " . ($index + 1) . ". " . basename($fileName) . "\n", Console::FG_GREEN); $this->stdout(" " . ($index + 1) . ". " . basename($fileName) . "\n", Console::FG_GREEN);
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
namespace yii\base; namespace yii\base;
use Yii;
/** /**
* Request represents a request that is handled by an [[Application]]. * Request represents a request that is handled by an [[Application]].
...@@ -72,7 +73,7 @@ abstract class Request extends Component ...@@ -72,7 +73,7 @@ abstract class Request extends Component
*/ */
public function setScriptFile($value) public function setScriptFile($value)
{ {
$scriptFile = realpath(\Yii::getAlias($value)); $scriptFile = realpath(Yii::getAlias($value));
if ($scriptFile !== false && is_file($scriptFile)) { if ($scriptFile !== false && is_file($scriptFile)) {
$this->_scriptFile = $scriptFile; $this->_scriptFile = $scriptFile;
} else { } else {
......
...@@ -227,8 +227,7 @@ class AssetManager extends Component ...@@ -227,8 +227,7 @@ class AssetManager extends Component
return $this->_published[$path]; return $this->_published[$path];
} }
$src = realpath($path); if (!is_string($path) || ($src = realpath($path)) === false) {
if ($src === false) {
throw new InvalidParamException("The file or directory to be published does not exist: $path"); throw new InvalidParamException("The file or directory to be published does not exist: $path");
} }
...@@ -295,7 +294,7 @@ class AssetManager extends Component ...@@ -295,7 +294,7 @@ class AssetManager extends Component
if (isset($this->_published[$path])) { if (isset($this->_published[$path])) {
return $this->_published[$path][0]; return $this->_published[$path][0];
} }
if (($path = realpath($path)) !== false) { if (is_string($path) && ($path = realpath($path)) !== false) {
$base = $this->basePath . DIRECTORY_SEPARATOR; $base = $this->basePath . DIRECTORY_SEPARATOR;
if (is_file($path)) { if (is_file($path)) {
return $base . $this->hash(dirname($path) . filemtime($path)) . DIRECTORY_SEPARATOR . basename($path); return $base . $this->hash(dirname($path) . filemtime($path)) . DIRECTORY_SEPARATOR . basename($path);
...@@ -319,7 +318,7 @@ class AssetManager extends Component ...@@ -319,7 +318,7 @@ class AssetManager extends Component
if (isset($this->_published[$path])) { if (isset($this->_published[$path])) {
return $this->_published[$path][1]; return $this->_published[$path][1];
} }
if (($path = realpath($path)) !== false) { if (is_string($path) && ($path = realpath($path)) !== false) {
if (is_file($path)) { if (is_file($path)) {
return $this->baseUrl . '/' . $this->hash(dirname($path) . filemtime($path)) . '/' . basename($path); return $this->baseUrl . '/' . $this->hash(dirname($path) . filemtime($path)) . '/' . basename($path);
} 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