Skip to content
Snippets Groups Projects
Verified Commit 0a7c3372 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #2920678 by phenaproxima, Wim Leers, dawehner, Gogowitsch, Sam152, dww,...

Issue #2920678 by phenaproxima, Wim Leers, dawehner, Gogowitsch, Sam152, dww, longwave, yogeshmpawar, alexpott, borisson_, tstoeckler, jibran, amateescu, larowlan, tedbow: Add config validation for the allowed characters of machine names
parent da5ea0ae
No related branches found
No related tags found
43 merge requests!54479.5.x SF update,!5014Issue #3071143: Table Render Array Example Is Incorrect,!4868Issue #1428520: Improve menu parent link selection,!4594Applying patch for Views Global Text area field to allow extra HTML tags. As video, source and iframe tag is not rendering. Due to which Media embedded video and remote-video not rendering in Views Global Text area field.,!3878Removed unused condition head title for views,!38582585169-10.1.x,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3668Resolve #3347842 "Deprecate the trusted",!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3546refactored dialog.pcss file,!3531Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!3502Issue #3335308: Confusing behavior with FormState::setFormState and FormState::setMethod,!3452Issue #3332701: Refactor Claro's tablesort-indicator stylesheet,!3451Issue #2410579: Allows setting the current language programmatically.,!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3147Issue #3328457: Replace most substr($a, $i) where $i is negative with str_ends_with(),!3146Issue #3328456: Replace substr($a, 0, $i) with str_starts_with(),!3133core/modules/system/css/components/hidden.module.css,!31312878513-10.1.x,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2614Issue #2981326: Replace non-test usages of \Drupal::logger() with IoC injection,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2334Issue #3228209: Add hasRole() method to AccountInterface,!2062Issue #3246454: Add weekly granularity to views date sort,!1591Issue #3199697: Add JSON:API Translation experimental module,!1255Issue #3238922: Refactor (if feasible) uses of the jQuery serialize function to use vanillaJS,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!877Issue #2708101: Default value for link text is not saved,!844Resolve #3036010 "Updaters",!673Issue #3214208: FinishResponseSubscriber could create duplicate headers,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!485Sets the autocomplete attribute for username/password input field on login form.,!30Issue #3182188: Updates composer usage to point at ./vendor/bin/composer
Showing
with 168 additions and 18 deletions
......@@ -94,6 +94,16 @@ color_hex:
type: string
label: 'Color'
# Machine-readable identifier that can only contain certain characters.
machine_name:
type: string
label: 'Machine name'
constraints:
Regex: '/^[a-z0-9_]+$/'
Length:
# @see \Drupal\Core\Config\Entity\ConfigEntityStorage::MAX_ID_LENGTH
max: 166
# Complex extended data types:
# Root of a configuration object.
......
......@@ -5,8 +5,13 @@ block.block.*:
label: 'Block'
mapping:
id:
type: string
type: machine_name
label: 'ID'
# Blocks have atypical machine names: they allow periods for historical reasons.
# @see https://www.drupal.org/project/drupal/issues/2685917
# @see https://www.drupal.org/project/drupal/issues/2043527
constraints:
Regex: '/^[a-z0-9_.]+$/'
theme:
type: string
label: 'Theme'
......
......@@ -39,4 +39,18 @@ public function testInvalidPluginId(): void {
$this->assertValidationErrors(['plugin' => "The 'non_existent' plugin does not exist."]);
}
/**
* Block names are atypical in that they allow periods in the machine name.
*/
public function providerInvalidMachineNameCharacters(): array {
$cases = parent::providerInvalidMachineNameCharacters();
// Remove the existing test case that verifies a machine name containing
// periods is invalid.
$this->assertSame(['period.separated', FALSE], $cases['INVALID: period separated']);
unset($cases['INVALID: period separated']);
// And instead add a test case that verifies it is allowed for blocks.
$cases['VALID: period separated'] = ['period.separated', TRUE];
return $cases;
}
}
......@@ -5,7 +5,7 @@ block_content.type.*:
label: 'Block type settings'
mapping:
id:
type: string
type: machine_name
label: 'ID'
label:
type: label
......
......@@ -38,7 +38,7 @@ comment.type.*:
label: 'Comment type settings'
mapping:
id:
type: string
type: machine_name
label: 'ID'
label:
type: label
......
......@@ -5,8 +5,13 @@ contact.form.*:
label: 'Contact form'
mapping:
id:
type: string
type: machine_name
label: 'ID'
constraints:
Length:
# Contact form IDs are specifically limited to 32 characters.
# @see \Drupal\contact\ContactFormEditForm::form()
max: 32
label:
type: label
label: 'Label'
......
......@@ -19,8 +19,13 @@ filter.format.*:
type: label
label: 'Name'
format:
type: string
type: machine_name
label: 'Machine name'
# Filter format machine names can be up to 255 characters.
# @see \Drupal\filter\FilterFormatFormBase::form()
constraints:
Length:
max: 255
weight:
type: integer
label: 'Weight'
......
......@@ -5,7 +5,7 @@ image.style.*:
label: 'Image style'
mapping:
name:
type: string
type: machine_name
label:
type: label
label: 'Label'
......
......@@ -20,8 +20,13 @@ media.type.*:
label: 'Media type'
mapping:
id:
type: string
type: machine_name
label: 'Machine name'
constraints:
Length:
# Media type IDs are specifically limited to 32 characters.
# @see \Drupal\media\MediaTypeForm::form()
max: 32
label:
type: label
label: 'Name'
......
......@@ -24,7 +24,7 @@ class MediaTypeValidationTest extends ConfigEntityValidationTestBase {
*/
protected function setUp(): void {
parent::setUp();
$this->entity = $this->createMediaType('test');
$this->entity = $this->createMediaType('test', ['id' => 'test_media']);
}
}
......@@ -16,8 +16,13 @@ node.type.*:
type: label
label: 'Name'
type:
type: string
type: machine_name
label: 'Machine-readable name'
constraints:
# Node type machine names are specifically limited to 32 characters.
# @see \Drupal\node\NodeTypeForm::form()
Length:
max: 32
description:
type: text
label: 'Description'
......
......@@ -5,7 +5,7 @@ responsive_image.styles.*:
label: 'Responsive image style'
mapping:
id:
type: string
type: machine_name
label: 'Machine-readable name'
label:
type: label
......
......@@ -72,7 +72,7 @@ search.page.*:
label: 'Search page'
mapping:
id:
type: string
type: machine_name
label: 'ID'
label:
type: label
......
......@@ -5,8 +5,15 @@ shortcut.set.*:
label: 'Shortcut settings'
mapping:
id:
type: string
type: machine_name
label: 'ID'
# Shortcut set IDs are specifically limited to 23 characters, and allow
# dashes but not underscores.
# @see \Drupal\shortcut\ShortcutSetForm::form()
constraints:
Regex: '/^[a-z0-9-]+$/'
Length:
max: 23
label:
type: label
label: 'Label'
......
......@@ -26,10 +26,35 @@ protected function setUp(): void {
$this->installEntitySchema('shortcut');
$this->entity = ShortcutSet::create([
'id' => 'test',
'id' => 'test-shortcut-set',
'label' => 'Test',
]);
$this->entity->save();
}
/**
* Shortcut set IDs are atypical: they allow dashes and disallow underscores.
*/
public function providerInvalidMachineNameCharacters(): array {
$cases = parent::providerInvalidMachineNameCharacters();
// Remove the existing test case that verifies a machine name containing
// dashes is invalid.
$this->assertSame(['dash-separated', FALSE], $cases['INVALID: dash separated']);
unset($cases['INVALID: dash separated']);
// And instead add a test case that verifies it is allowed for shortcut
// sets.
$cases['VALID: dash separated'] = ['dash-separated', TRUE];
// Remove the existing test case that verifies a machine name containing
// underscores is valid.
$this->assertSame(['underscore_separated', TRUE], $cases['VALID: underscore separated']);
unset($cases['VALID: underscore separated']);
// And instead add a test case that verifies it is disallowed for shortcut
// sets.
$cases['INVALID: underscore separated'] = ['underscore_separated', FALSE];
return $cases;
}
}
......@@ -212,8 +212,15 @@ system.menu.*:
label: 'Menu'
mapping:
id:
type: string
type: machine_name
label: 'ID'
# Menu IDs are specifically limited to 32 characters, and allow dashes but not
# underscores.
# @see \Drupal\menu_ui\MenuForm::form()
constraints:
Regex: '/^[a-z0-9-]+$/'
Length:
max: 32
label:
type: label
label: 'Label'
......@@ -229,7 +236,7 @@ system.action.*:
label: 'System action'
mapping:
id:
type: string
type: machine_name
label: 'ID'
label:
type: label
......
......@@ -19,10 +19,33 @@ protected function setUp(): void {
parent::setUp();
$this->entity = Menu::create([
'id' => 'test',
'id' => 'test-menu',
'label' => 'Test',
]);
$this->entity->save();
}
/**
* Menu IDs are atypical: they allow dashes and disallow underscores.
*/
public function providerInvalidMachineNameCharacters(): array {
$cases = parent::providerInvalidMachineNameCharacters();
// Remove the existing test case that verifies a machine name containing
// dashes is invalid.
$this->assertSame(['dash-separated', FALSE], $cases['INVALID: dash separated']);
unset($cases['INVALID: dash separated']);
// And instead add a test case that verifies it is allowed for menus.
$cases['VALID: dash separated'] = ['dash-separated', TRUE];
// Remove the existing test case that verifies a machine name containing
// underscores is valid.
$this->assertSame(['underscore_separated', TRUE], $cases['VALID: underscore separated']);
unset($cases['VALID: underscore separated']);
// And instead add a test case that verifies it is disallowed for menus.
$cases['INVALID: underscore separated'] = ['underscore_separated', FALSE];
return $cases;
}
}
......@@ -22,8 +22,13 @@ taxonomy.vocabulary.*:
type: label
label: 'Name'
vid:
type: string
type: machine_name
label: 'Machine name'
# Vocabulary machine names are specifically limited to 32 characters.
# @see \Drupal\taxonomy\VocabularyForm::form()
constraints:
Length:
max: 32
description:
type: label
label: 'Description'
......
......@@ -5,7 +5,7 @@ tour.tour.*:
label: 'Tour settings'
mapping:
id:
type: string
type: machine_name
label: 'ID'
label:
type: label
......
<?php
namespace Drupal\Tests\tour\Kernel;
use Drupal\KernelTests\Core\Config\ConfigEntityValidationTestBase;
use Drupal\tour\Entity\Tour;
/**
* Tests validation of tour entities.
*
* @group tour
*/
class TourValidationTest extends ConfigEntityValidationTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['tour'];
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->entity = Tour::create([
'id' => 'test',
'label' => 'Test',
'module' => 'system',
]);
$this->entity->save();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment