From: Alexander Ebert Date: Wed, 7 Jun 2017 10:08:25 +0000 (+0200) Subject: Guard against invalid selection ranges X-Git-Tag: 3.0.6~20 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=9d65beb9f405940b1f0f5e4a22e53570cc18c0f0;p=GitHub%2FWoltLab%2FWCF.git Guard against invalid selection ranges --- diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Format.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Format.js index 23332b2ed9..5e8c2bad4d 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Format.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Format.js @@ -11,6 +11,19 @@ define(['Dom/Util'], function(DomUtil) { "use strict"; + var _isValidSelection = function(editorElement) { + var element = window.getSelection().anchorNode; + while (element) { + if (element === editorElement) { + return true; + } + + element = element.parentNode; + } + + return false; + }; + /** * @exports WoltLabSuite/Core/Ui/Redactor/Format */ @@ -29,6 +42,11 @@ define(['Dom/Util'], function(DomUtil) { return; } + if (!_isValidSelection(editorElement)) { + console.error("Invalid selection, range exists outside of the editor:", selection.anchorNode); + return; + } + var range = selection.getRangeAt(0); var markerStart = null, markerEnd = null, tmpElement = null; if (range.collapsed) { @@ -190,6 +208,15 @@ define(['Dom/Util'], function(DomUtil) { * @param {string} property CSS property that should be removed */ removeFormat: function(editorElement, property) { + var selection = window.getSelection(); + if (!selection.rangeCount) { + return; + } + else if (!_isValidSelection(editorElement)) { + console.error("Invalid selection, range exists outside of the editor:", selection.anchorNode); + return; + } + var strikeElements = elByTag('strike', editorElement); // remove any element first, all though there shouldn't be any at all