From: Alexander Ebert Date: Mon, 8 May 2023 10:05:44 +0000 (+0200) Subject: Replace the recursive call in `unwrapBr` with a loop X-Git-Tag: 6.0.0_Alpha_1~136^2~4 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=18eddcae0e80ad0e8c686b97f0552055f7f38d3c;p=GitHub%2FWoltLab%2FWCF.git Replace the recursive call in `unwrapBr` with a loop --- diff --git a/ts/WoltLabSuite/Core/Component/Ckeditor/Cleanup.ts b/ts/WoltLabSuite/Core/Component/Ckeditor/Cleanup.ts index 14719cde89..fee08a6a5e 100644 --- a/ts/WoltLabSuite/Core/Component/Ckeditor/Cleanup.ts +++ b/ts/WoltLabSuite/Core/Component/Ckeditor/Cleanup.ts @@ -21,26 +21,29 @@ function normalizeBr(div: HTMLElement): void { } function unwrapBr(br: HTMLElement): void { - if (br.previousSibling || br.nextSibling) { - return; - } + for (;;) { + if (br.previousSibling || br.nextSibling) { + return; + } - const parent = br.parentElement!; - switch (parent.tagName) { - case "B": - case "DEL": - case "EM": - case "I": - case "STRONG": - case "SUB": - case "SUP": - case "SPAN": - case "U": - parent.insertAdjacentElement("afterend", br); - parent.remove(); - - unwrapBr(br); - break; + const parent = br.parentElement!; + switch (parent.tagName) { + case "B": + case "DEL": + case "EM": + case "I": + case "STRONG": + case "SUB": + case "SUP": + case "SPAN": + case "U": + parent.insertAdjacentElement("afterend", br); + parent.remove(); + break; + + default: + return; + } } } diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor/Cleanup.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor/Cleanup.js index 925cfcf603..3e0f18b1d0 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor/Cleanup.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor/Cleanup.js @@ -22,24 +22,27 @@ define(["require", "exports", "tslib", "../../Dom/Util"], function (require, exp }); } function unwrapBr(br) { - if (br.previousSibling || br.nextSibling) { - return; - } - const parent = br.parentElement; - switch (parent.tagName) { - case "B": - case "DEL": - case "EM": - case "I": - case "STRONG": - case "SUB": - case "SUP": - case "SPAN": - case "U": - parent.insertAdjacentElement("afterend", br); - parent.remove(); - unwrapBr(br); - break; + for (;;) { + if (br.previousSibling || br.nextSibling) { + return; + } + const parent = br.parentElement; + switch (parent.tagName) { + case "B": + case "DEL": + case "EM": + case "I": + case "STRONG": + case "SUB": + case "SUP": + case "SPAN": + case "U": + parent.insertAdjacentElement("afterend", br); + parent.remove(); + break; + default: + return; + } } } function removeTrailingBr(br) { diff --git a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeNormalizer.class.php b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeNormalizer.class.php index 85dc429555..d6c3437958 100644 --- a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeNormalizer.class.php +++ b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeNormalizer.class.php @@ -104,26 +104,29 @@ final class HtmlOutputNodeNormalizer private function unwrapBr(\DOMElement $br): void { - if ($br->previousSibling || $br->nextSibling) { - return; - } + for (;;) { + if ($br->previousSibling || $br->nextSibling) { + return; + } - $parent = $br->parentNode; - switch ($parent->nodeName) { - case "b": - case "del": - case "em": - case "i": - case "strong": - case "sub": - case "sup": - case "span": - case "u": - $parent->parentNode->insertBefore($br, $parent); - $parent->parentNode->removeChild($parent); - - $this->unwrapBr($br); - break; + $parent = $br->parentNode; + switch ($parent->nodeName) { + case "b": + case "del": + case "em": + case "i": + case "strong": + case "sub": + case "sup": + case "span": + case "u": + $parent->parentNode->insertBefore($br, $parent); + $parent->parentNode->removeChild($parent); + break; + + default: + return; + } } }