From b71fa7bff90f7caa03ea3bb5a247800154210ab6 Mon Sep 17 00:00:00 2001 From: Arushad Ahmed Date: Tue, 12 Mar 2024 20:34:21 +0500 Subject: [PATCH 1/6] Update ComponentTagCompiler.php - Fixed bound attributes not rendering for non-data attributes, see pull request #50403 --- src/Illuminate/View/Compilers/ComponentTagCompiler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/View/Compilers/ComponentTagCompiler.php b/src/Illuminate/View/Compilers/ComponentTagCompiler.php index 02bd4b7b1003..0826dc91fed7 100644 --- a/src/Illuminate/View/Compilers/ComponentTagCompiler.php +++ b/src/Illuminate/View/Compilers/ComponentTagCompiler.php @@ -805,7 +805,7 @@ protected function attributesToStringWithExistingComponentData(array $attributes } $results[] = "'{$attribute}' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(".( - ($attribute === 'attributes') ? $value : ('$componentData[\'data\'][\''.Str::camel($attribute).'\'] ?? null') + ($attribute === 'attributes') ? $value : ('$componentData[\'data\'][\''.Str::camel($attribute).'\'] ?? ' . $value) ).')'; } From 21b361a67de89e9a1b6a431354c24d9e81dc2484 Mon Sep 17 00:00:00 2001 From: Arushad Ahmed Date: Tue, 12 Mar 2024 21:01:46 +0500 Subject: [PATCH 2/6] Update src/Illuminate/View/Compilers/ComponentTagCompiler.php Co-authored-by: Dan Harrin --- src/Illuminate/View/Compilers/ComponentTagCompiler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/View/Compilers/ComponentTagCompiler.php b/src/Illuminate/View/Compilers/ComponentTagCompiler.php index 0826dc91fed7..38e22548a8b2 100644 --- a/src/Illuminate/View/Compilers/ComponentTagCompiler.php +++ b/src/Illuminate/View/Compilers/ComponentTagCompiler.php @@ -805,7 +805,7 @@ protected function attributesToStringWithExistingComponentData(array $attributes } $results[] = "'{$attribute}' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(".( - ($attribute === 'attributes') ? $value : ('$componentData[\'data\'][\''.Str::camel($attribute).'\'] ?? ' . $value) + ($attribute === 'attributes') ? $value : ('array_key_exists(\''.Str::camel($attribute).'\', $componentData[\'data\'] ?? []) ? ($componentData[\'data\'][\''.Str::camel($attribute).'\'] ?? null) : ' . $value) ).')'; } From 0b6826a1fb4a2e4bfc3a106c01d4c2a7bbbb3f5a Mon Sep 17 00:00:00 2001 From: Arushad Ahmed Date: Tue, 12 Mar 2024 21:04:54 +0500 Subject: [PATCH 3/6] Update ComponentTagCompiler.php --- src/Illuminate/View/Compilers/ComponentTagCompiler.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/View/Compilers/ComponentTagCompiler.php b/src/Illuminate/View/Compilers/ComponentTagCompiler.php index 38e22548a8b2..803dd752a9fb 100644 --- a/src/Illuminate/View/Compilers/ComponentTagCompiler.php +++ b/src/Illuminate/View/Compilers/ComponentTagCompiler.php @@ -804,8 +804,10 @@ protected function attributesToStringWithExistingComponentData(array $attributes continue; } + $camelCaseAttribute = Str::camel($attribute); + $results[] = "'{$attribute}' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(".( - ($attribute === 'attributes') ? $value : ('array_key_exists(\''.Str::camel($attribute).'\', $componentData[\'data\'] ?? []) ? ($componentData[\'data\'][\''.Str::camel($attribute).'\'] ?? null) : ' . $value) + ($attribute === 'attributes') ? $value : ('array_key_exists(\''.$camelCaseAttribute.'\', $componentData[\'data\'] ?? []) ? ($componentData[\'data\'][\''.$camelCaseAttribute.'\'] ?? null) : ' . $value) ).')'; } From aab9706a633a7b4e077a38d45f6857a0838a485f Mon Sep 17 00:00:00 2001 From: Arushad Ahmed Date: Tue, 12 Mar 2024 21:22:14 +0500 Subject: [PATCH 4/6] Updated blade component compiler tests to match the new format --- .../View/Blade/BladeComponentTagCompilerTest.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/View/Blade/BladeComponentTagCompilerTest.php b/tests/View/Blade/BladeComponentTagCompilerTest.php index 0335f216e96e..886d4acb5d1a 100644 --- a/tests/View/Blade/BladeComponentTagCompilerTest.php +++ b/tests/View/Blade/BladeComponentTagCompilerTest.php @@ -265,7 +265,7 @@ public function testColonAttributesIsEscapedIfStrings() getConstructor()): ?> except(collect(\$constructor->getParameters())->map->getName()->all()); ?> -withAttributes(['src' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(\$componentData['data']['src'] ?? null)]); ?> @endComponentClass##END-COMPONENT-CLASS##", trim($result)); +withAttributes(['src' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('src', $componentData['data'] ?? []) ? (\$componentData['data']['src'] ?? null) : 'foo')]); ?> @endComponentClass##END-COMPONENT-CLASS##", trim($result)); } public function testClassDirective() @@ -277,7 +277,7 @@ public function testClassDirective() getConstructor()): ?> except(collect(\$constructor->getParameters())->map->getName()->all()); ?> -withAttributes(['class' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(\$componentData['data']['class'] ?? null)]); ?> @endComponentClass##END-COMPONENT-CLASS##", trim($result)); +withAttributes(['class' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('class', $componentData['data'] ?? []) ? (\$componentData['data']['class'] ?? null) : \Illuminate\Support\Arr::toCssClasses(['bar'=>true]))]); ?> @endComponentClass##END-COMPONENT-CLASS##", trim($result)); } public function testStyleDirective() @@ -289,7 +289,7 @@ public function testStyleDirective() getConstructor()): ?> except(collect(\$constructor->getParameters())->map->getName()->all()); ?> -withAttributes(['style' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(\$componentData['data']['style'] ?? null)]); ?> @endComponentClass##END-COMPONENT-CLASS##", trim($result)); +withAttributes(['style' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('style', $componentData['data'] ?? []) ? (\$componentData['data']['style'] ?? null) : \Illuminate\Support\Arr::toCssStyles(['bar'=>true]))]); ?> @endComponentClass##END-COMPONENT-CLASS##", trim($result)); } public function testColonNestedComponentParsing() @@ -478,7 +478,7 @@ public function testClasslessComponents() getConstructor()): ?> except(collect(\$constructor->getParameters())->map->getName()->all()); ?> -withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(\$componentData['data']['name'] ?? null),'age' => 31,'wire:model' => 'foo']); ?>\n". +withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('src', $componentData['data'] ?? []) ? (\$componentData['data']['src'] ?? null) : 'Taylor'),'age' => 31,'wire:model' => 'foo']); ?>\n". '@endComponentClass##END-COMPONENT-CLASS##', trim($result)); } @@ -497,7 +497,7 @@ public function testClasslessComponentsWithIndexView() getConstructor()): ?> except(collect(\$constructor->getParameters())->map->getName()->all()); ?> -withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(\$componentData['data']['name'] ?? null),'age' => 31,'wire:model' => 'foo']); ?>\n". +withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('src', $componentData['data'] ?? []) ? (\$componentData['data']['src'] ?? null) : 'Taylor'),'age' => 31,'wire:model' => 'foo']); ?>\n". '@endComponentClass##END-COMPONENT-CLASS##', trim($result)); } @@ -516,7 +516,7 @@ public function testPackagesClasslessComponents() getConstructor()): ?> except(collect(\$constructor->getParameters())->map->getName()->all()); ?> -withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(\$componentData['data']['name'] ?? null),'age' => 31,'wire:model' => 'foo']); ?>\n". +withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('src', $componentData['data'] ?? []) ? (\$componentData['data']['src'] ?? null) : 'Taylor'),'age' => 31,'wire:model' => 'foo']); ?>\n". '@endComponentClass##END-COMPONENT-CLASS##', trim($result)); } @@ -550,7 +550,7 @@ public function testClasslessComponentsWithAnonymousComponentNamespace() getConstructor()): ?> except(collect(\$constructor->getParameters())->map->getName()->all()); ?> -withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(\$componentData['data']['name'] ?? null),'age' => 31,'wire:model' => 'foo']); ?>\n". +withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('src', $componentData['data'] ?? []) ? (\$componentData['data']['src'] ?? null) : 'Taylor'),'age' => 31,'wire:model' => 'foo']); ?>\n". '@endComponentClass##END-COMPONENT-CLASS##', trim($result)); } @@ -584,7 +584,7 @@ public function testClasslessComponentsWithAnonymousComponentNamespaceWithIndexV getConstructor()): ?> except(collect(\$constructor->getParameters())->map->getName()->all()); ?> -withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(\$componentData['data']['name'] ?? null),'age' => 31,'wire:model' => 'foo']); ?>\n". +withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('src', $componentData['data'] ?? []) ? (\$componentData['data']['src'] ?? null) : 'Taylor'),'age' => 31,'wire:model' => 'foo']); ?>\n". '@endComponentClass##END-COMPONENT-CLASS##', trim($result)); } From 876cdd939af3d6f55481ecb46fb7b146f4c69b88 Mon Sep 17 00:00:00 2001 From: Arushad Ahmed Date: Tue, 12 Mar 2024 21:25:53 +0500 Subject: [PATCH 5/6] Fixed BladeComponentCompiler tests --- tests/View/Blade/BladeComponentTagCompilerTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/View/Blade/BladeComponentTagCompilerTest.php b/tests/View/Blade/BladeComponentTagCompilerTest.php index 886d4acb5d1a..054f152c4f8a 100644 --- a/tests/View/Blade/BladeComponentTagCompilerTest.php +++ b/tests/View/Blade/BladeComponentTagCompilerTest.php @@ -478,7 +478,7 @@ public function testClasslessComponents() getConstructor()): ?> except(collect(\$constructor->getParameters())->map->getName()->all()); ?> -withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('src', $componentData['data'] ?? []) ? (\$componentData['data']['src'] ?? null) : 'Taylor'),'age' => 31,'wire:model' => 'foo']); ?>\n". +withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('name', $componentData['data'] ?? []) ? (\$componentData['data']['name'] ?? null) : 'Taylor'),'age' => 31,'wire:model' => 'foo']); ?>\n". '@endComponentClass##END-COMPONENT-CLASS##', trim($result)); } @@ -497,7 +497,7 @@ public function testClasslessComponentsWithIndexView() getConstructor()): ?> except(collect(\$constructor->getParameters())->map->getName()->all()); ?> -withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('src', $componentData['data'] ?? []) ? (\$componentData['data']['src'] ?? null) : 'Taylor'),'age' => 31,'wire:model' => 'foo']); ?>\n". +withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('name', $componentData['data'] ?? []) ? (\$componentData['data']['name'] ?? null) : 'Taylor'),'age' => 31,'wire:model' => 'foo']); ?>\n". '@endComponentClass##END-COMPONENT-CLASS##', trim($result)); } @@ -516,7 +516,7 @@ public function testPackagesClasslessComponents() getConstructor()): ?> except(collect(\$constructor->getParameters())->map->getName()->all()); ?> -withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('src', $componentData['data'] ?? []) ? (\$componentData['data']['src'] ?? null) : 'Taylor'),'age' => 31,'wire:model' => 'foo']); ?>\n". +withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('name', $componentData['data'] ?? []) ? (\$componentData['data']['name'] ?? null) : 'Taylor'),'age' => 31,'wire:model' => 'foo']); ?>\n". '@endComponentClass##END-COMPONENT-CLASS##', trim($result)); } @@ -550,7 +550,7 @@ public function testClasslessComponentsWithAnonymousComponentNamespace() getConstructor()): ?> except(collect(\$constructor->getParameters())->map->getName()->all()); ?> -withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('src', $componentData['data'] ?? []) ? (\$componentData['data']['src'] ?? null) : 'Taylor'),'age' => 31,'wire:model' => 'foo']); ?>\n". +withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('name', $componentData['data'] ?? []) ? (\$componentData['data']['name'] ?? null) : 'Taylor'),'age' => 31,'wire:model' => 'foo']); ?>\n". '@endComponentClass##END-COMPONENT-CLASS##', trim($result)); } @@ -584,7 +584,7 @@ public function testClasslessComponentsWithAnonymousComponentNamespaceWithIndexV getConstructor()): ?> except(collect(\$constructor->getParameters())->map->getName()->all()); ?> -withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('src', $componentData['data'] ?? []) ? (\$componentData['data']['src'] ?? null) : 'Taylor'),'age' => 31,'wire:model' => 'foo']); ?>\n". +withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('name', $componentData['data'] ?? []) ? (\$componentData['data']['name'] ?? null) : 'Taylor'),'age' => 31,'wire:model' => 'foo']); ?>\n". '@endComponentClass##END-COMPONENT-CLASS##', trim($result)); } From 5a1345a57e5425b6bbcff568482d0346bd9b8859 Mon Sep 17 00:00:00 2001 From: Arushad Ahmed Date: Tue, 12 Mar 2024 21:29:55 +0500 Subject: [PATCH 6/6] Update BladeComponentTagCompilerTest.php --- .../View/Blade/BladeComponentTagCompilerTest.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/View/Blade/BladeComponentTagCompilerTest.php b/tests/View/Blade/BladeComponentTagCompilerTest.php index 054f152c4f8a..5bef185f41bf 100644 --- a/tests/View/Blade/BladeComponentTagCompilerTest.php +++ b/tests/View/Blade/BladeComponentTagCompilerTest.php @@ -265,7 +265,7 @@ public function testColonAttributesIsEscapedIfStrings() getConstructor()): ?> except(collect(\$constructor->getParameters())->map->getName()->all()); ?> -withAttributes(['src' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('src', $componentData['data'] ?? []) ? (\$componentData['data']['src'] ?? null) : 'foo')]); ?> @endComponentClass##END-COMPONENT-CLASS##", trim($result)); +withAttributes(['src' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('src', \$componentData['data'] ?? []) ? (\$componentData['data']['src'] ?? null) : 'foo')]); ?> @endComponentClass##END-COMPONENT-CLASS##", trim($result)); } public function testClassDirective() @@ -277,7 +277,7 @@ public function testClassDirective() getConstructor()): ?> except(collect(\$constructor->getParameters())->map->getName()->all()); ?> -withAttributes(['class' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('class', $componentData['data'] ?? []) ? (\$componentData['data']['class'] ?? null) : \Illuminate\Support\Arr::toCssClasses(['bar'=>true]))]); ?> @endComponentClass##END-COMPONENT-CLASS##", trim($result)); +withAttributes(['class' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('class', \$componentData['data'] ?? []) ? (\$componentData['data']['class'] ?? null) : \Illuminate\Support\Arr::toCssClasses(['bar'=>true]))]); ?> @endComponentClass##END-COMPONENT-CLASS##", trim($result)); } public function testStyleDirective() @@ -289,7 +289,7 @@ public function testStyleDirective() getConstructor()): ?> except(collect(\$constructor->getParameters())->map->getName()->all()); ?> -withAttributes(['style' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('style', $componentData['data'] ?? []) ? (\$componentData['data']['style'] ?? null) : \Illuminate\Support\Arr::toCssStyles(['bar'=>true]))]); ?> @endComponentClass##END-COMPONENT-CLASS##", trim($result)); +withAttributes(['style' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('style', \$componentData['data'] ?? []) ? (\$componentData['data']['style'] ?? null) : \Illuminate\Support\Arr::toCssStyles(['bar'=>true]))]); ?> @endComponentClass##END-COMPONENT-CLASS##", trim($result)); } public function testColonNestedComponentParsing() @@ -478,7 +478,7 @@ public function testClasslessComponents() getConstructor()): ?> except(collect(\$constructor->getParameters())->map->getName()->all()); ?> -withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('name', $componentData['data'] ?? []) ? (\$componentData['data']['name'] ?? null) : 'Taylor'),'age' => 31,'wire:model' => 'foo']); ?>\n". +withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('name', \$componentData['data'] ?? []) ? (\$componentData['data']['name'] ?? null) : 'Taylor'),'age' => 31,'wire:model' => 'foo']); ?>\n". '@endComponentClass##END-COMPONENT-CLASS##', trim($result)); } @@ -497,7 +497,7 @@ public function testClasslessComponentsWithIndexView() getConstructor()): ?> except(collect(\$constructor->getParameters())->map->getName()->all()); ?> -withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('name', $componentData['data'] ?? []) ? (\$componentData['data']['name'] ?? null) : 'Taylor'),'age' => 31,'wire:model' => 'foo']); ?>\n". +withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('name', \$componentData['data'] ?? []) ? (\$componentData['data']['name'] ?? null) : 'Taylor'),'age' => 31,'wire:model' => 'foo']); ?>\n". '@endComponentClass##END-COMPONENT-CLASS##', trim($result)); } @@ -516,7 +516,7 @@ public function testPackagesClasslessComponents() getConstructor()): ?> except(collect(\$constructor->getParameters())->map->getName()->all()); ?> -withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('name', $componentData['data'] ?? []) ? (\$componentData['data']['name'] ?? null) : 'Taylor'),'age' => 31,'wire:model' => 'foo']); ?>\n". +withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('name', \$componentData['data'] ?? []) ? (\$componentData['data']['name'] ?? null) : 'Taylor'),'age' => 31,'wire:model' => 'foo']); ?>\n". '@endComponentClass##END-COMPONENT-CLASS##', trim($result)); } @@ -550,7 +550,7 @@ public function testClasslessComponentsWithAnonymousComponentNamespace() getConstructor()): ?> except(collect(\$constructor->getParameters())->map->getName()->all()); ?> -withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('name', $componentData['data'] ?? []) ? (\$componentData['data']['name'] ?? null) : 'Taylor'),'age' => 31,'wire:model' => 'foo']); ?>\n". +withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('name', \$componentData['data'] ?? []) ? (\$componentData['data']['name'] ?? null) : 'Taylor'),'age' => 31,'wire:model' => 'foo']); ?>\n". '@endComponentClass##END-COMPONENT-CLASS##', trim($result)); } @@ -584,7 +584,7 @@ public function testClasslessComponentsWithAnonymousComponentNamespaceWithIndexV getConstructor()): ?> except(collect(\$constructor->getParameters())->map->getName()->all()); ?> -withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('name', $componentData['data'] ?? []) ? (\$componentData['data']['name'] ?? null) : 'Taylor'),'age' => 31,'wire:model' => 'foo']); ?>\n". +withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(array_key_exists('name', \$componentData['data'] ?? []) ? (\$componentData['data']['name'] ?? null) : 'Taylor'),'age' => 31,'wire:model' => 'foo']); ?>\n". '@endComponentClass##END-COMPONENT-CLASS##', trim($result)); }