enh: URL checking for import web addresses (#2377)
* enh: URL checking for import web addresses * Add the source for Regex * Removing the console.log for production
This commit is contained in:
parent
8b94b142cb
commit
3fd3faca11
@ -80,7 +80,7 @@
|
|||||||
"core-index-import/warning-data-file": "You must specify a data file to import.",
|
"core-index-import/warning-data-file": "You must specify a data file to import.",
|
||||||
"core-index-import/uploading-data": "Uploading data…",
|
"core-index-import/uploading-data": "Uploading data…",
|
||||||
"core-index-import/web-address": "Web Addresses (URLs)",
|
"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/downloading-data": "Downloading data…",
|
||||||
"core-index-import/clipboard": "Clipboard",
|
"core-index-import/clipboard": "Clipboard",
|
||||||
"core-index-import/warning-clipboard": "You must paste some data to import.",
|
"core-index-import/warning-clipboard": "You must paste some data to import.",
|
||||||
|
@ -34,6 +34,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
function ThisComputerImportingSourceUI(controller) {
|
function ThisComputerImportingSourceUI(controller) {
|
||||||
this._controller = 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({
|
Refine.DefaultImportingController.sources.push({
|
||||||
"label": $.i18n('core-index-import/this-computer'),
|
"label": $.i18n('core-index-import/this-computer'),
|
||||||
"id": "upload",
|
"id": "upload",
|
||||||
@ -83,7 +90,7 @@ UrlImportingSourceUI.prototype.attachUI = function(bodyDiv) {
|
|||||||
this._elmts.nextButton.html($.i18n('core-buttons/next'));
|
this._elmts.nextButton.html($.i18n('core-buttons/next'));
|
||||||
|
|
||||||
this._elmts.nextButton.click(function(evt) {
|
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'));
|
window.alert($.i18n('core-index-import/warning-web-address'));
|
||||||
} else {
|
} else {
|
||||||
self._controller.startImportJob(self._elmts.form, $.i18n('core-index-import/downloading-data'));
|
self._controller.startImportJob(self._elmts.form, $.i18n('core-index-import/downloading-data'));
|
||||||
|
Loading…
Reference in New Issue
Block a user