From a9c54fca0643c322cdff2b15fdcf1ac6d2d6e42b Mon Sep 17 00:00:00 2001 From: nod_ Date: Fri, 4 Apr 2025 09:29:29 +0200 Subject: [PATCH] Issue #3517317 by penyaskito, larowlan: SDC slots not being validated against json config schema (cherry picked from commit 96c70753fe5c5760a24af8f337eab2f8e6ec7980) --- core/assets/schemas/v1/metadata-full.schema.json | 2 +- core/assets/schemas/v1/metadata.schema.json | 2 +- .../Theme/Component/ComponentValidatorTest.php | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/core/assets/schemas/v1/metadata-full.schema.json b/core/assets/schemas/v1/metadata-full.schema.json index 8df83fb05c9..b5c0d89c089 100644 --- a/core/assets/schemas/v1/metadata-full.schema.json +++ b/core/assets/schemas/v1/metadata-full.schema.json @@ -5,7 +5,7 @@ "slotDefinition": { "type": "object", "patternProperties": { - "^[a-zA-Z0-9_-]$": { + "^[a-zA-Z0-9_-]+$": { "type": "object", "properties": { "title": { diff --git a/core/assets/schemas/v1/metadata.schema.json b/core/assets/schemas/v1/metadata.schema.json index 4cbeffebff1..0fa340cb3c9 100644 --- a/core/assets/schemas/v1/metadata.schema.json +++ b/core/assets/schemas/v1/metadata.schema.json @@ -5,7 +5,7 @@ "slotDefinition": { "type": "object", "patternProperties": { - "^[a-zA-Z0-9_-]$": { + "^[a-zA-Z0-9_-]+$": { "type": "object", "properties": { "title": { diff --git a/core/tests/Drupal/Tests/Core/Theme/Component/ComponentValidatorTest.php b/core/tests/Drupal/Tests/Core/Theme/Component/ComponentValidatorTest.php index a0ae10e4790..ff79612b494 100644 --- a/core/tests/Drupal/Tests/Core/Theme/Component/ComponentValidatorTest.php +++ b/core/tests/Drupal/Tests/Core/Theme/Component/ComponentValidatorTest.php @@ -102,6 +102,22 @@ class ComponentValidatorTest extends TestCase { // allowed as the allowed type. $cta_with_non_string_prop_type['props']['properties']['text']['type'] = ['string', []]; yield 'non string type (Array)' => [$cta_with_non_string_prop_type]; + + $cta_with_invalid_slot_type = $valid_cta; + $cta_with_invalid_slot_type['slots'] = [ + 'valid_slot' => [ + 'title' => 'Valid slot', + 'description' => 'Valid slot description', + ], + 'invalid_slot' => [ + 'title' => [ + 'hello' => 'Invalid slot', + 'world' => 'Invalid slot', + ], + 'description' => 'Title must be string', + ], + ]; + yield 'invalid slot (type)' => [$cta_with_invalid_slot_type]; } /**