diff --git a/src/Illuminate/View/ComponentAttributeBag.php b/src/Illuminate/View/ComponentAttributeBag.php index 607f4d134301..ea2d67d4d53c 100644 --- a/src/Illuminate/View/ComponentAttributeBag.php +++ b/src/Illuminate/View/ComponentAttributeBag.php @@ -278,6 +278,10 @@ protected function shouldEscapeAttributeValue($escape, $value) return false; } + if ($value instanceof AppendableAttributeValue) { + return $this->shouldEscapeAttributeValue($escape, $value->value); + } + return ! is_object($value) && ! is_null($value) && ! is_bool($value); diff --git a/tests/View/ViewComponentAttributeBagTest.php b/tests/View/ViewComponentAttributeBagTest.php index a2293e6e5f19..2cb054992df2 100644 --- a/tests/View/ViewComponentAttributeBagTest.php +++ b/tests/View/ViewComponentAttributeBagTest.php @@ -2,6 +2,7 @@ namespace Illuminate\Tests\View; +use Illuminate\View\AppendableAttributeValue; use Illuminate\View\ComponentAttributeBag; use PHPUnit\Framework\TestCase; @@ -63,6 +64,19 @@ public function testAttributeRetrieval() $this->assertSame('test-escaped="<tag attr="attr">"', (string) $bag); + $bag = (new ComponentAttributeBag) + ->merge([ + 'data-bs-tooltip' => new AppendableAttributeValue('Sample Title'), + ]); + + $this->assertSame('data-bs-tooltip="<strong>Sample Title</strong>"', (string) $bag); + + $bag = $bag->merge([ + 'data-bs-tooltip' => new AppendableAttributeValue('First Text'), + ]); + + $this->assertSame('data-bs-tooltip="<em>First Text</em> <strong>Sample Title</strong>"', (string) $bag); + $bag = (new ComponentAttributeBag) ->merge([ 'test-string' => 'ok',