From b3a30bae55de7c79bc8719a50cd097bf29b8b203 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Sat, 30 Oct 2021 00:51:41 +0100
Subject: [PATCH] Issue #3227821 by wtrv: Broken svg element with "Auto convert
 linebreaks" (autop) filter

---
 core/modules/filter/filter.module                         | 2 +-
 core/modules/filter/tests/src/Kernel/FilterKernelTest.php | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/core/modules/filter/filter.module b/core/modules/filter/filter.module
index 70661d97ce86..04d73fce7aaf 100644
--- a/core/modules/filter/filter.module
+++ b/core/modules/filter/filter.module
@@ -690,7 +690,7 @@ function _filter_autop($text) {
   // to avoid messing up code. We look for matched pairs and allow basic
   // nesting. For example:
   // "processed <pre> ignored <script> ignored </script> ignored </pre> processed"
-  $chunks = preg_split('@(<!--.*?-->|</?(?:pre|script|style|object|iframe|drupal-media|!--)[^>]*>)@i', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
+  $chunks = preg_split('@(<!--.*?-->|</?(?:pre|script|style|object|iframe|drupal-media|svg|!--)[^>]*>)@i', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
   // Note: PHP ensures the array consists of alternating delimiters and literals
   // and begins and ends with a literal (inserting NULL as required).
   $ignore = FALSE;
diff --git a/core/modules/filter/tests/src/Kernel/FilterKernelTest.php b/core/modules/filter/tests/src/Kernel/FilterKernelTest.php
index f26a1b4286f1..f51f86a6710d 100644
--- a/core/modules/filter/tests/src/Kernel/FilterKernelTest.php
+++ b/core/modules/filter/tests/src/Kernel/FilterKernelTest.php
@@ -336,12 +336,14 @@ public function testLineBreakFilter() {
 <pre>aaa\nbbb\n\nccc</pre>
 <object>aaa\nbbb\n\nccc</object>
 <iframe>aaa\nbbb\n\nccc</iframe>
+<svg>aaa\nbbb\n\nccc</svg>
 " => [
         "<script>aaa\nbbb\n\nccc</script>" => TRUE,
         "<style>aaa\nbbb\n\nccc</style>" => TRUE,
         "<pre>aaa\nbbb\n\nccc</pre>" => TRUE,
         "<object>aaa\nbbb\n\nccc</object>" => TRUE,
         "<iframe>aaa\nbbb\n\nccc</iframe>" => TRUE,
+        "<svg>aaa\nbbb\n\nccc</svg>" => TRUE,
       ],
       // Skip comments entirely.
       "One. <!-- comment --> Two.\n<!--\nThree.\n-->\n" => [
-- 
GitLab