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
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -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.
+6 −1
Original line number Diff line number Diff line
@@ -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'
+14 −0
Original line number Diff line number Diff line
@@ -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;
  }

}
+1 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ block_content.type.*:
  label: 'Block type settings'
  mapping:
    id:
      type: string
      type: machine_name
      label: 'ID'
    label:
      type: label
+1 −1
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ comment.type.*:
  label: 'Comment type settings'
  mapping:
    id:
      type: string
      type: machine_name
      label: 'ID'
    label:
      type: label
Loading