From 8fb2f0f45fc4a2788f4696594b4d2788f5261afc Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 28 Jul 2016 17:42:15 +0200 Subject: [PATCH] Added link validation for quotes --- com.woltlab.wcf/templates/wysiwyg.tpl | 1 + .../files/js/WoltLab/WCF/Ui/Redactor/Quote.js | 21 ++++++++++++++++--- wcfsetup/install/lang/de.xml | 1 + wcfsetup/install/lang/en.xml | 1 + 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/com.woltlab.wcf/templates/wysiwyg.tpl b/com.woltlab.wcf/templates/wysiwyg.tpl index cd19fe024d..fd5ff2922e 100644 --- a/com.woltlab.wcf/templates/wysiwyg.tpl +++ b/com.woltlab.wcf/templates/wysiwyg.tpl @@ -79,6 +79,7 @@ 'wcf.editor.quote.title': '{lang __literal=true}wcf.editor.quote.title{/lang}', 'wcf.editor.quote.url': '{lang}wcf.editor.quote.url{/lang}', 'wcf.editor.quote.url.description': '{lang}wcf.editor.quote.url.description{/lang}', + 'wcf.editor.quote.url.error.invalid': '{lang}wcf.editor.quote.url.error.invalid{/lang}', 'wcf.editor.spoiler.label': '{lang}wcf.editor.spoiler.label{/lang}', 'wcf.editor.spoiler.label.description': '{lang}wcf.editor.spoiler.label.description{/lang}', diff --git a/wcfsetup/install/files/js/WoltLab/WCF/Ui/Redactor/Quote.js b/wcfsetup/install/files/js/WoltLab/WCF/Ui/Redactor/Quote.js index f1bdd6a270..b9871e66be 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/Ui/Redactor/Quote.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/Ui/Redactor/Quote.js @@ -173,10 +173,25 @@ define(['Core', 'EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util' event.preventDefault(); var id = 'redactor-quote-' + this._elementId; + var urlInput = elById(id + '-url'); + var innerError = elBySel('.innerError', urlInput.parentNode); + if (innerError !== null) elRemove(innerError); - ['author', 'url'].forEach((function (attr) { - elData(this._blockquote, attr, elById(id + '-' + attr).value); - }).bind(this)); + var url = urlInput.value.replace(/\u200B/g, '').trim(); + // simple test to check if it at least looks like it could be a valid url + if (url.length && !/^https?:\/\/[^\/]+/.test(url)) { + innerError = elCreate('small'); + innerError.className = 'innerError'; + innerError.textContent = Language.get('wcf.editor.quote.url.error.invalid'); + urlInput.parentNode.insertBefore(innerError, urlInput.nextElementSibling); + return; + } + + // set author + elData(this._blockquote, 'author', elById(id + '-author').value); + + // set url + elData(this._blockquote, 'url', url); this._setTitle(this._blockquote); this._editor.caret.after(this._blockquote); diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 94c29c12c0..9c56410197 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -2281,6 +2281,7 @@ Fehler sind beispielsweise: + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 793d2b9276..5a4be539a9 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -2258,6 +2258,7 @@ Errors are: + -- 2.20.1