diff --git a/main/webapp/modules/core/langs/translation-en.json b/main/webapp/modules/core/langs/translation-en.json index 856f3ad34..3f17bd3de 100644 --- a/main/webapp/modules/core/langs/translation-en.json +++ b/main/webapp/modules/core/langs/translation-en.json @@ -80,7 +80,7 @@ "core-index-import/warning-data-file": "You must specify a data file to import.", "core-index-import/uploading-data": "Uploading data…", "core-index-import/web-address": "Web Addresses (URLs)", - "core-index-import/warning-web-address": "You must specify a web address (URL) to import.", + "core-index-import/warning-web-address": "You must specify a valid web address (URL) to import.", "core-index-import/downloading-data": "Downloading data…", "core-index-import/clipboard": "Clipboard", "core-index-import/warning-clipboard": "You must paste some data to import.", diff --git a/main/webapp/modules/core/scripts/index/default-importing-sources/sources.js b/main/webapp/modules/core/scripts/index/default-importing-sources/sources.js index f46468d38..b625dc2a3 100644 --- a/main/webapp/modules/core/scripts/index/default-importing-sources/sources.js +++ b/main/webapp/modules/core/scripts/index/default-importing-sources/sources.js @@ -34,6 +34,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. function ThisComputerImportingSourceUI(controller) { this._controller = controller; } + +// Function to check if the URL getting entered is valid or not +function isUrlValid(url) { + // regex for a valid URL pattern + // Derived from the jquery-validation repository https://github.com/jquery-validation/jquery-validation/blob/master/src/additional/url2.js + return /^(https?|s?ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(url); +} Refine.DefaultImportingController.sources.push({ "label": $.i18n('core-index-import/this-computer'), "id": "upload", @@ -83,7 +90,7 @@ UrlImportingSourceUI.prototype.attachUI = function(bodyDiv) { this._elmts.nextButton.html($.i18n('core-buttons/next')); this._elmts.nextButton.click(function(evt) { - if ($.trim(self._elmts.urlInput[0].value).length === 0) { + if(!isUrlValid(self._elmts.urlInput[0].value)) { window.alert($.i18n('core-index-import/warning-web-address')); } else { self._controller.startImportJob(self._elmts.form, $.i18n('core-index-import/downloading-data'));