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

[7.x] Blade newline fixes #32026

Merged
merged 1 commit into from
Mar 19, 2020
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
4 changes: 2 additions & 2 deletions src/Illuminate/View/Compilers/BladeCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ protected function getRawPlaceholder($replace)
*/
protected function addFooters($result)
{
return ltrim($result, PHP_EOL)
.PHP_EOL.implode(PHP_EOL, array_reverse($this->footer));
return ltrim($result, "\n")
."\n".implode("\n", array_reverse($this->footer));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/View/Compilers/Concerns/CompilesComponents.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static function newComponentHash(string $component)
*/
public static function compileClassComponentOpening(string $component, string $data, string $hash)
{
return implode(PHP_EOL, [
return implode("\n", [
'<?php if (isset($component)) { $__componentOriginal'.$hash.' = $component; } ?>',
'<?php $component = $__env->getContainer()->make('.Str::finish($component, '::class').', '.($data ?: '[]').'); ?>',
'<?php if ($component->shouldRender()): ?>',
Expand All @@ -76,7 +76,7 @@ protected function compileEndComponent()
{
$hash = array_pop(static::$componentHashStack);

return implode(PHP_EOL, [
return implode("\n", [
'<?php if (isset($__componentOriginal'.$hash.')): ?>',
'<?php $component = $__componentOriginal'.$hash.'; ?>',
'<?php unset($__componentOriginal'.$hash.'); ?>',
Expand All @@ -92,7 +92,7 @@ protected function compileEndComponent()
*/
public function compileEndComponentClass()
{
return static::compileEndComponent().PHP_EOL.implode(PHP_EOL, [
return static::compileEndComponent()."\n".implode("\n", [
'<?php endif; ?>',
]);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/View/Blade/BladeComponentTagCompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testSlotsCanBeCompiled()
$result = (new ComponentTagCompiler)->compileSlots('<x-slot name="foo">
</x-slot>');

$this->assertSame("@slot('foo') ".PHP_EOL.' @endslot', trim($result));
$this->assertSame("@slot('foo') \n".' @endslot', trim($result));
}

public function testBasicComponentParsing()
Expand Down
12 changes: 6 additions & 6 deletions tests/View/Blade/BladeExtendsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ public function testExtendsAreCompiled()
{
$string = '@extends(\'foo\')
test';
$expected = 'test'.PHP_EOL.'<?php echo $__env->make(\'foo\', \Illuminate\Support\Arr::except(get_defined_vars(), [\'__data\', \'__path\']))->render(); ?>';
$expected = "test\n".'<?php echo $__env->make(\'foo\', \Illuminate\Support\Arr::except(get_defined_vars(), [\'__data\', \'__path\']))->render(); ?>';
$this->assertEquals($expected, $this->compiler->compileString($string));

$string = '@extends(name(foo))'.PHP_EOL.'test';
$expected = 'test'.PHP_EOL.'<?php echo $__env->make(name(foo), \Illuminate\Support\Arr::except(get_defined_vars(), [\'__data\', \'__path\']))->render(); ?>';
$string = '@extends(name(foo))'."\n".'test';
$expected = "test\n".'<?php echo $__env->make(name(foo), \Illuminate\Support\Arr::except(get_defined_vars(), [\'__data\', \'__path\']))->render(); ?>';
$this->assertEquals($expected, $this->compiler->compileString($string));
}

public function testSequentialCompileStringCalls()
{
$string = '@extends(\'foo\')
test';
$expected = 'test'.PHP_EOL.'<?php echo $__env->make(\'foo\', \Illuminate\Support\Arr::except(get_defined_vars(), [\'__data\', \'__path\']))->render(); ?>';
$expected = "test\n".'<?php echo $__env->make(\'foo\', \Illuminate\Support\Arr::except(get_defined_vars(), [\'__data\', \'__path\']))->render(); ?>';
$this->assertEquals($expected, $this->compiler->compileString($string));

// use the same compiler instance to compile another template with @extends directive
$string = '@extends(name(foo))'.PHP_EOL.'test';
$expected = 'test'.PHP_EOL.'<?php echo $__env->make(name(foo), \Illuminate\Support\Arr::except(get_defined_vars(), [\'__data\', \'__path\']))->render(); ?>';
$string = "@extends(name(foo))\ntest";
$expected = "test\n".'<?php echo $__env->make(name(foo), \Illuminate\Support\Arr::except(get_defined_vars(), [\'__data\', \'__path\']))->render(); ?>';
$this->assertEquals($expected, $this->compiler->compileString($string));
}
}