Skip to content

Commit

Permalink
Merge pull request #27976 from bzixilu/5.8
Browse files Browse the repository at this point in the history
[5.8] don't add the path if it's null or empty
  • Loading branch information
taylorotwell authored Mar 22, 2019
2 parents e3593ad + 883e07a commit 5d459fa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/Illuminate/View/Compilers/BladeCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,17 @@ public function compile($path = null)
}

if (! is_null($this->cachePath)) {
$contents = $this->compileString($this->files->get($this->getPath())).
"\n<?php /* {$this->getPath()} */ ?>";
$contents = $this->compileString(
$this->files->get($this->getPath())
);

$this->files->put($this->getCompiledPath($this->getPath()), $contents);
if (! empty($this->getPath())) {
$contents .= "\n<?php /* {$this->getPath()} */ ?>";
}

$this->files->put(
$this->getCompiledPath($this->getPath()), $contents
);
}
}

Expand Down
18 changes: 18 additions & 0 deletions tests/View/ViewBladeCompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,24 @@ public function testIncludePathToTemplate()
$compiler->compile('foo');
}

public function testDontIncludeEmptyPath()
{
$compiler = new BladeCompiler($files = $this->getFiles(), __DIR__);
$files->shouldReceive('get')->once()->with('')->andReturn('Hello World');
$files->shouldReceive('put')->once()->with(__DIR__.'/'.sha1('').'.php', 'Hello World');
$compiler->setPath('');
$compiler->compile();
}

public function testDontIncludeNullPath()
{
$compiler = new BladeCompiler($files = $this->getFiles(), __DIR__);
$files->shouldReceive('get')->once()->with(null)->andReturn('Hello World');
$files->shouldReceive('put')->once()->with(__DIR__.'/'.sha1(null).'.php', 'Hello World');
$compiler->setPath(null);
$compiler->compile();
}

public function testShouldStartFromStrictTypesDeclaration()
{
$compiler = new BladeCompiler($files = $this->getFiles(), __DIR__);
Expand Down

0 comments on commit 5d459fa

Please sign in to comment.