diff --git a/core/modules/big_pipe/src/Tests/BigPipePlaceholderTestCases.php b/core/modules/big_pipe/src/Tests/BigPipePlaceholderTestCases.php
index 1cf10d4dc14257c221918b347c913d50891e05b0..49719ec0962412269fc11bc2b9ccc3c6af4f1f78 100644
--- a/core/modules/big_pipe/src/Tests/BigPipePlaceholderTestCases.php
+++ b/core/modules/big_pipe/src/Tests/BigPipePlaceholderTestCases.php
@@ -110,7 +110,7 @@ public static function cases(ContainerInterface $container = NULL, AccountInterf
           'command' => 'insert',
           'method' => 'replaceWith',
           'selector' => '[data-big-pipe-placeholder-id="callback=Drupal%5CCore%5CRender%5CElement%5CStatusMessages%3A%3ArenderMessages&args[0]&token=a8c34b5e"]',
-          'data' => "\n" . '    <div role="contentinfo" aria-label="Status message" class="messages messages--status">' . "\n" . '                  <h2 class="visually-hidden">Status message</h2>' . "\n" . '                    Hello from BigPipe!' . "\n" . '            </div>' . "\n    \n",
+          'data' => "\n" . '    <div role="contentinfo" aria-label="Status message" class="messages messages--status">' . "\n" . '                  <h2 class="visually-hidden">Status message</h2>' . "\n" . '                    Hello from BigPipe!' . "\n" . '            </div>' . "\n    ",
           'settings' => NULL,
         ],
       ];
diff --git a/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.module b/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.module
index 550b5ca1730beaa4610c839c3bcc9a22d155ddcc..b3a75e5180cca394764fb14e5a21ad6fdd97d36f 100644
--- a/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.module
+++ b/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.module
@@ -114,3 +114,10 @@ function _test_theme_twig_php_values() {
     ),
   );
 }
+
+/**
+ * Implements template_preprocess_status_messages().
+ */
+function twig_theme_test_preprocess_status_messages(&$variables) {
+  $variables['attributes']['class'][] = 'custom-test-messages-class';
+}
diff --git a/core/modules/system/tests/src/Kernel/Render/ClassyTest.php b/core/modules/system/tests/src/Kernel/Render/ClassyTest.php
new file mode 100644
index 0000000000000000000000000000000000000000..76cf23ee6346107ba1178c41c9864b45174e3f10
--- /dev/null
+++ b/core/modules/system/tests/src/Kernel/Render/ClassyTest.php
@@ -0,0 +1,49 @@
+<?php
+
+namespace Drupal\Tests\system\Kernel\Render;
+
+use Drupal\KernelTests\KernelTestBase;
+
+/**
+ * Tests the Classy theme.
+ *
+ * @group Theme
+ */
+class ClassyTest extends KernelTestBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public static $modules = array('system', 'twig_theme_test');
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setUp() {
+    parent::setUp();
+
+    // Use the classy theme.
+    $this->container->get('theme_installer')->install(['classy']);
+    $this->container->get('config.factory')
+      ->getEditable('system.theme')
+      ->set('default', 'classy')
+      ->save();
+    // Clear the theme registry.
+    $this->container->set('theme.registry', NULL);
+
+  }
+
+  /**
+   * Test the classy theme.
+   */
+  function testClassyTheme() {
+    drupal_set_message('An error occurred', 'error');
+    drupal_set_message('But then something nice happened');
+    $messages = array(
+      '#type' => 'status_messages',
+    );
+    $this->render($messages);
+    $this->assertNoText('custom-test-messages-class', 'The custom class attribute value added in the status messages preprocess function is not displayed as page content.');
+  }
+
+}
diff --git a/core/themes/classy/templates/misc/status-messages.html.twig b/core/themes/classy/templates/misc/status-messages.html.twig
index 683a111d2605538294b39ef277512799b091f404..bc8fd106c2a483d4b5afe0c0f2867a4711021513 100644
--- a/core/themes/classy/templates/misc/status-messages.html.twig
+++ b/core/themes/classy/templates/misc/status-messages.html.twig
@@ -51,6 +51,6 @@
     {% endif %}
   </div>
   {# Remove type specific classes. #}
-  {{ attributes.removeClass(classes) }}
+  {% set attributes = attributes.removeClass(classes) %}
 {% endfor %}
 {% endblock messages %}