From 8a2166faff9904f4106ffd05ecc6d174426623ba Mon Sep 17 00:00:00 2001 From: NickSdot Date: Thu, 30 Oct 2025 16:07:55 +0700 Subject: [PATCH 1/2] style --- src/Illuminate/View/ComponentAttributeBag.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/View/ComponentAttributeBag.php b/src/Illuminate/View/ComponentAttributeBag.php index 607f4d134301..c656ccb186f9 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); From 9def3f535c53bf772193242d8f9d9be5a4900096 Mon Sep 17 00:00:00 2001 From: NickSdot Date: Thu, 30 Oct 2025 16:04:55 +0700 Subject: [PATCH 2/2] refactor: unblocked against https://github.com/laravel/framework/pull/57467 --- src/Illuminate/View/ComponentAttributeBag.php | 4 ++-- tests/View/ViewComponentAttributeBagTest.php | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Illuminate/View/ComponentAttributeBag.php b/src/Illuminate/View/ComponentAttributeBag.php index c656ccb186f9..28e5715340f9 100644 --- a/src/Illuminate/View/ComponentAttributeBag.php +++ b/src/Illuminate/View/ComponentAttributeBag.php @@ -495,10 +495,10 @@ public function __toString() $value = $key === 'x-data' || str_starts_with($key, 'wire:') ? '' : $key; } - if ($key === $value) { + if($key === $value) { $string .= ' '.$key; } else { - $string .= ' '.$key.'="'.str_replace('"', '\\"', trim($value)).'"'; + $string .= ' ' . $key . '="' . str_replace('"', '\\"', trim($value)) . '"'; } } 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()