diff --git a/src/Illuminate/View/ComponentAttributeBag.php b/src/Illuminate/View/ComponentAttributeBag.php index 607f4d134301..28e5715340f9 100644 --- a/src/Illuminate/View/ComponentAttributeBag.php +++ b/src/Illuminate/View/ComponentAttributeBag.php @@ -495,7 +495,11 @@ public function __toString() $value = $key === 'x-data' || str_starts_with($key, 'wire:') ? '' : $key; } - $string .= ' '.$key.'="'.str_replace('"', '\\"', trim($value)).'"'; + if($key === $value) { + $string .= ' '.$key; + } else { + $string .= ' ' . $key . '="' . str_replace('"', '\\"', trim($value)) . '"'; + } } return trim($string); diff --git a/tests/View/ViewComponentAttributeBagTest.php b/tests/View/ViewComponentAttributeBagTest.php index a2293e6e5f19..4f0e12bb038e 100644 --- a/tests/View/ViewComponentAttributeBagTest.php +++ b/tests/View/ViewComponentAttributeBagTest.php @@ -53,8 +53,8 @@ public function testAttributeRetrieval() 'test-empty-string' => '', ]); - $this->assertSame('test-string="ok" test-true="test-true" test-0="0" test-0-string="0" test-empty-string=""', (string) $bag); - $this->assertSame('test-string="ok" test-true="test-true" test-0="0" test-0-string="0" test-empty-string=""', (string) $bag->merge()); + $this->assertSame('test-string="ok" test-true test-0="0" test-0-string="0" test-empty-string=""', (string) $bag); + $this->assertSame('test-string="ok" test-true test-0="0" test-0-string="0" test-empty-string=""', (string) $bag->merge()); $bag = (new ComponentAttributeBag) ->merge([ @@ -74,7 +74,7 @@ public function testAttributeRetrieval() 'test-empty-string' => '', ]); - $this->assertSame('test-string="ok" test-true="test-true" test-0="0" test-0-string="0" test-empty-string=""', (string) $bag); + $this->assertSame('test-string="ok" test-true test-0="0" test-0-string="0" test-empty-string=""', (string) $bag); $bag = (new ComponentAttributeBag) ->merge([ @@ -151,7 +151,7 @@ public function testItMakesAnExceptionForAlpineXdata() 'x-data' => true, ]); - $this->assertSame('required="required" x-data=""', (string) $bag); + $this->assertSame('required x-data=""', (string) $bag); } public function testItMakesAnExceptionForLivewireWireAttributes()