Added link validation for quotes
authorAlexander Ebert <ebert@woltlab.com>
Thu, 28 Jul 2016 15:42:15 +0000 (17:42 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 28 Jul 2016 15:42:35 +0000 (17:42 +0200)
com.woltlab.wcf/templates/wysiwyg.tpl
wcfsetup/install/files/js/WoltLab/WCF/Ui/Redactor/Quote.js
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index cd19fe024db6e54e1579c8ad4d6a2a198241fd87..fd5ff2922e5a1da0482e9361ce7fbfc650928594 100644 (file)
@@ -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}',
index f1bdd6a270f2215eed0bb2621007ae39403eb5e3..b9871e66bed34490962b6cee255dc2814b7d8fa3 100644 (file)
@@ -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);
index 94c29c12c0ba7415efb8b53db30ee9d4895f99a5..9c564101971cd5d8427cec6cf84d4f199aa29aae 100644 (file)
@@ -2281,6 +2281,7 @@ Fehler sind beispielsweise:
                <item name="wcf.editor.quote.title"><![CDATA[{if $author}Zitat von {$author}{else}Zitat{/if}]]></item>
                <item name="wcf.editor.quote.url"><![CDATA[Link]]></item>
                <item name="wcf.editor.quote.url.description"><![CDATA[Optional: {if LANGUAGE_USE_INFORMAL_VARIANT}Gib{else}Geben Sie{/if} einen Link zu der Quelle an.]]></item>
+               <item name="wcf.editor.quote.url.error.invalid"><![CDATA[Der eingegebene Link ist ungültig.]]></item>
                
                <item name="wcf.editor.spoiler.label"><![CDATA[Beschriftung]]></item>
                <item name="wcf.editor.spoiler.label.description"><![CDATA[Optional: {if LANGUAGE_USE_INFORMAL_VARIANT}Gib{else}Geben Sie{/if} eine Beschriftung für den Spoiler-Button ein.]]></item>
index 793d2b9276300986b73afef92dc306d1800695b7..5a4be539a929f026dc794e07749d4c18804955e1 100644 (file)
@@ -2258,6 +2258,7 @@ Errors are:
                <item name="wcf.editor.quote.title"><![CDATA[{if $author}Quote from {$author}{else}Quote{/if}]]></item>
                <item name="wcf.editor.quote.url"><![CDATA[Link]]></item>
                <item name="wcf.editor.quote.url.description"><![CDATA[Optional: Specify the link to the source.]]></item>
+               <item name="wcf.editor.quote.url.error.invalid"><![CDATA[You have entered an invalid link.]]></item>
                
                <item name="wcf.editor.spoiler.label"><![CDATA[Label]]></item>
                <item name="wcf.editor.spoiler.label.description"><![CDATA[Optional: Specify the label for the spoiler toggle button.]]></item>