From 609b8a60f64c14f18649e3a3ff38f1002e3deb99 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Tue, 12 Jul 2016 12:53:01 -0700 Subject: [PATCH] Do not allow empty cache paths --- src/Illuminate/View/Compilers/Compiler.php | 9 ++++++++- tests/View/ViewBladeCompilerTest.php | 17 +++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Illuminate/View/Compilers/Compiler.php b/src/Illuminate/View/Compilers/Compiler.php index a11a6d530807..0e546344fffb 100755 --- a/src/Illuminate/View/Compilers/Compiler.php +++ b/src/Illuminate/View/Compilers/Compiler.php @@ -2,6 +2,7 @@ namespace Illuminate\View\Compilers; +use InvalidArgumentException; use Illuminate\Filesystem\Filesystem; abstract class Compiler @@ -26,9 +27,15 @@ abstract class Compiler * @param \Illuminate\Filesystem\Filesystem $files * @param string $cachePath * @return void + * + * @throws \InvalidArgumentException */ public function __construct(Filesystem $files, $cachePath) { + if (! $cachePath) { + throw new InvalidArgumentException('The cache path must be non-empty.'); + } + $this->files = $files; $this->cachePath = $cachePath; } @@ -57,7 +64,7 @@ public function isExpired($path) // If the compiled file doesn't exist we will indicate that the view is expired // so that it can be re-compiled. Else, we will verify the last modification // of the views is less than the modification times of the compiled views. - if (! $this->cachePath || ! $this->files->exists($compiled)) { + if (! $this->files->exists($compiled)) { return true; } diff --git a/tests/View/ViewBladeCompilerTest.php b/tests/View/ViewBladeCompilerTest.php index 26713a1210a4..b9445975b9c4 100644 --- a/tests/View/ViewBladeCompilerTest.php +++ b/tests/View/ViewBladeCompilerTest.php @@ -17,11 +17,12 @@ public function testIsExpiredReturnsTrueIfCompiledFileDoesntExist() $this->assertTrue($compiler->isExpired('foo')); } - public function testIsExpiredReturnsTrueIfCachePathIsNull() + /** + * @expectedException \InvalidArgumentException + */ + public function testCannotConstructWithBadCachePath() { - $compiler = new BladeCompiler($files = $this->getFiles(), null); - $files->shouldReceive('exists')->never(); - $this->assertTrue($compiler->isExpired('foo')); + new BladeCompiler($this->getFiles(), null); } public function testIsExpiredReturnsTrueWhenModificationTimesWarrant() @@ -75,14 +76,6 @@ public function testCompileWithPathSetBefore() $this->assertEquals('foo', $compiler->getPath()); } - public function testCompileDoesntStoreFilesWhenCachePathIsNull() - { - $compiler = new BladeCompiler($files = $this->getFiles(), null); - $files->shouldReceive('get')->once()->with('foo')->andReturn('Hello World'); - $files->shouldReceive('put')->never(); - $compiler->compile('foo'); - } - public function testEchosAreCompiled() { $compiler = new BladeCompiler($this->getFiles(), __DIR__);