From 0c9c57f14c0072e9eaf59c9392f48c2a718283f8 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Fri, 31 Jul 2020 18:22:24 +0100
Subject: [PATCH] Issue #2911527 by harsha012, b_sharpe, Chris Burge, Manav,
 jibran, Waldoswndrwrld, christinlepson, vacho, mttsmmrssprks,
 nicholasThompson, Wim Leers, othermachines, Sutharsan: Allow dashes in Styles
 dropdown's element names

---
 .../src/Plugin/CKEditorPlugin/StylesCombo.php      |  2 +-
 .../Functional/CKEditorStylesComboAdminTest.php    |  5 ++---
 .../ckeditor/tests/src/Kernel/CKEditorTest.php     | 14 ++++++++++++++
 3 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/core/modules/ckeditor/src/Plugin/CKEditorPlugin/StylesCombo.php b/core/modules/ckeditor/src/Plugin/CKEditorPlugin/StylesCombo.php
index c839f7b42bc3..c6d4df3a4d83 100644
--- a/core/modules/ckeditor/src/Plugin/CKEditorPlugin/StylesCombo.php
+++ b/core/modules/ckeditor/src/Plugin/CKEditorPlugin/StylesCombo.php
@@ -141,7 +141,7 @@ protected function generateStylesSetSetting($styles) {
       }
 
       // Validate syntax: element[.class...]|label pattern expected.
-      if (!preg_match('@^ *[a-zA-Z0-9]+ *(\\.[a-zA-Z0-9_-]+ *)*\\| *.+ *$@', $style)) {
+      if (!preg_match('@^ *[a-zA-Z0-9-]+ *(\\.[a-zA-Z0-9_-]+ *)*\\| *.+ *$@', $style)) {
         return FALSE;
       }
 
diff --git a/core/modules/ckeditor/tests/src/Functional/CKEditorStylesComboAdminTest.php b/core/modules/ckeditor/tests/src/Functional/CKEditorStylesComboAdminTest.php
index d2d1186ffcfd..0afbd741bedf 100644
--- a/core/modules/ckeditor/tests/src/Functional/CKEditorStylesComboAdminTest.php
+++ b/core/modules/ckeditor/tests/src/Functional/CKEditorStylesComboAdminTest.php
@@ -80,10 +80,10 @@ public function testExistingFormat() {
     // and ensure the updated settings are saved.
     $this->drupalGet('admin/config/content/formats/manage/' . $this->format);
     $edit = [
-      'editor[settings][plugins][stylescombo][styles]' => "h1.title|Title\np.callout|Callout\n\n",
+      'editor[settings][plugins][stylescombo][styles]' => "h1.title|Title\np.callout|Callout\ndrupal-entity.has-dashes|Allowing Dashes\n\n",
     ];
     $this->drupalPostForm(NULL, $edit, t('Save configuration'));
-    $expected_settings['plugins']['stylescombo']['styles'] = "h1.title|Title\np.callout|Callout\n\n";
+    $expected_settings['plugins']['stylescombo']['styles'] = "h1.title|Title\np.callout|Callout\ndrupal-entity.has-dashes|Allowing Dashes\n\n";
     $editor = Editor::load($this->format);
     $this->assertEqual($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.');
 
@@ -96,7 +96,6 @@ public function testExistingFormat() {
     ];
     $this->drupalPostForm(NULL, $edit, t('Save configuration'));
     $this->assertRaw(t('Each style must have a unique label.'));
-    $expected_settings['plugins']['stylescombo']['styles'] = "h1.title|Title\np.callout|Callout\n\n";
     $editor = Editor::load($this->format);
     $this->assertEqual($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.');
   }
diff --git a/core/modules/ckeditor/tests/src/Kernel/CKEditorTest.php b/core/modules/ckeditor/tests/src/Kernel/CKEditorTest.php
index b796d0a239f4..68d2b64d3490 100644
--- a/core/modules/ckeditor/tests/src/Kernel/CKEditorTest.php
+++ b/core/modules/ckeditor/tests/src/Kernel/CKEditorTest.php
@@ -369,6 +369,20 @@ public function testStylesComboGetConfig() {
     $editor->save();
     $expected['stylesSet'] = FALSE;
     $this->assertIdentical($expected, $stylescombo_plugin->getConfig($editor), '"StylesCombo" plugin configuration built correctly for customized toolbar.');
+
+    // Configuration that includes a dash in either the element or class name.
+    $settings['plugins']['stylescombo']['styles'] = "drupal-entity.has-dashes|Allowing Dashes";
+    $editor->setSettings($settings);
+    $editor->save();
+    $expected['stylesSet'] = [
+      [
+        'name' => 'Allowing Dashes',
+        'element' => 'drupal-entity',
+        'attributes' => ['class' => 'has-dashes'],
+      ],
+    ];
+    $this->assertIdentical($expected, $stylescombo_plugin->getConfig($editor), '"StylesCombo" plugin configuration built correctly for customized toolbar.');
+
   }
 
   /**
-- 
GitLab