Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.1] Do not allow empty cache paths #14291

Merged
merged 1 commit into from
Jul 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Illuminate/View/Compilers/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\View\Compilers;

use InvalidArgumentException;
use Illuminate\Filesystem\Filesystem;

abstract class Compiler
Expand All @@ -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.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"non-empty" might be ambiguous in this context.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's ok. false and null are "empty" in php.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant because it's referring to a path which might be empty (not contain any files).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, one of these may be better:

  • The cache path must be a non-empty value.
  • The cache path must not be an empty value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's been changed in d9ed009

}

$this->files = $files;
$this->cachePath = $cachePath;
}
Expand Down Expand Up @@ -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;
}

Expand Down
17 changes: 5 additions & 12 deletions tests/View/ViewBladeCompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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__);
Expand Down