diff --git a/extensions/database/module/langs/translation-en.json b/extensions/database/module/langs/translation-en.json index 2feb01e3c..b4ffadf48 100644 --- a/extensions/database/module/langs/translation-en.json +++ b/extensions/database/module/langs/translation-en.json @@ -44,5 +44,10 @@ "database-parsing/limit-next": "Load at most", "database-parsing/limit": "row(s) of data", "database-parsing/store-row": "Store blank rows", - "database-parsing/store-cell": "Store blank cells as nulls" + "database-parsing/store-cell": "Store blank cells as nulls", + "database-source/alert-conn-name-invalid-character": "Connection Name Input Error: Illegal Character in Input. Only [a-zA-Z0-9._-] Allowed", + "database-source/alert-db-host-invalid-character": "Database Host Error: Illegal Character in Input. Only Alphanumeric characters allowed", + "database-source/alert-db-user-invalid-character": "Database User Error: Illegal Character in Input. Only Alphanumeric characters allowed", + "database-source/alert-db-port-invalid-character": "Database Port Error: Illegal Character in Input. Only Numeric values allowed." + } diff --git a/extensions/database/module/scripts/index/database-source-ui.js b/extensions/database/module/scripts/index/database-source-ui.js index 7b5932c2e..666f772d3 100644 --- a/extensions/database/module/scripts/index/database-source-ui.js +++ b/extensions/database/module/scripts/index/database-source-ui.js @@ -127,11 +127,11 @@ Refine.DatabaseSourceUI.prototype.attachUI = function(body) { this._elmts.saveConnectionButton.click(function(evt) { if(self._validateNewConnectionForm() == true){ - var connectionNameInput = $.trim(self._elmts.connectionNameInput[0].value); + var connectionNameInput = $.trim(self._elmts.connectionNameInput[0].value); if (connectionNameInput.length === 0) { window.alert($.i18n('database-source/alert-connection-name')); } else{ - self._saveConnection(self._getConnectionInfo()); + self._saveConnection(self._getConnectionInfo()); } } @@ -431,6 +431,9 @@ Refine.DatabaseSourceUI.prototype._getConnectionInfo = function() { var self = this; var jdbcConnectionInfo = {}; jdbcConnectionInfo.connectionName = $.trim(self._elmts.connectionNameInput[0].value); + + // window.alert('input:' + jdbcConnectionInfo.connectionName + ' output:' + self._removeScriptTag(jdbcConnectionInfo.connectionName) ); + jdbcConnectionInfo.databaseType = $.trim(self._elmts.databaseTypeSelect[0].value); jdbcConnectionInfo.databaseServer = $.trim(self._elmts.databaseHostInput[0].value); jdbcConnectionInfo.databasePort = $.trim(self._elmts.databasePortInput[0].value); @@ -442,6 +445,18 @@ Refine.DatabaseSourceUI.prototype._getConnectionInfo = function() { } +Refine.DatabaseSourceUI.prototype._removeScriptTag = function(input) { + var div = document.createElement('div'); + div.innerHTML = s; + var scripts = div.getElementsByTagName('script'); + var i = scripts.length; + while (i--) { + scripts[i].parentNode.removeChild(scripts[i]); + } + return div.innerHTML; +}; + + Refine.DatabaseSourceUI.prototype._validateNewConnectionForm = function() { var self = this; @@ -454,21 +469,45 @@ Refine.DatabaseSourceUI.prototype._validateNewConnectionForm = function() { var initialDatabaseInput = $.trim(self._elmts.initialDatabaseInput[0].value); var initialSchemaInput = $.trim(self._elmts.initialSchemaInput[0].value); - if (databaseHostInput.length === 0) { + var alphaNumRE = /^[a-zA-Z0-9._-]*$/; + var numRE = /^[0-9]*$/; + + var alphaNumConnNameTestResult = alphaNumRE.test(connectionNameInput); + var databaseHostTestResult = alphaNumRE.test(databaseHostInput); + var databasePortTestResult = numRE.test(databasePortInput); + var databaseUserTestResult = alphaNumRE.test(databaseUserInput); + + if(alphaNumConnNameTestResult == false){ + window.alert($.i18n('database-source/alert-conn-name-invalid-character')); + return false; + }else if(connectionNameInput.contains("