Jelajahi Sumber

Merge pull request #440 from smiclea/trim-inputs

Trim all text inputs except passwords
Dorin Paslaru 6 tahun lalu
induk
melakukan
33b27ecbae

+ 2 - 1
src/plugins/endpoint/default/ConnectionSchemaPlugin.js

@@ -15,6 +15,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 // @flow
 
 import LabelDictionary from '../../../utils/LabelDictionary'
+import Utils from '../../../utils/ObjectUtils'
 import type { Schema, SchemaProperties, SchemaDefinitions } from '../../../types/Schema'
 import type { Field } from '../../../types/Field'
 
@@ -96,7 +97,7 @@ export const fieldsToPayload = (data: { [string]: mixed }, schema: SchemaPropert
 
   Object.keys(schema.properties).forEach(fieldName => {
     if (data[fieldName] && typeof data[fieldName] !== 'object') {
-      info[fieldName] = data[fieldName]
+      info[fieldName] = Utils.trim(fieldName, data[fieldName])
     } else if (
       !data[fieldName] &&
       schema.required && schema.required.find(f => f === fieldName) &&

+ 5 - 3
src/plugins/endpoint/default/OptionsSchemaPlugin.js

@@ -16,6 +16,8 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import { defaultSchemaToFields } from './ConnectionSchemaPlugin'
 
+import Utils from '../../../utils/ObjectUtils'
+
 import type { Field } from '../../../types/Field'
 import type { OptionValues, StorageMap } from '../../../types/Endpoint'
 import type { SchemaProperties, SchemaDefinitions } from '../../../types/Schema'
@@ -82,15 +84,15 @@ export const defaultGetDestinationEnv = (options: ?{ [string]: mixed }, oldOptio
     if (specialOptions.find(o => o === optionName) || !options || options[optionName] == null || options[optionName] === '') {
       return
     }
-
     if (optionName.indexOf('/') > 0) {
       let parentName = optionName.substr(0, optionName.lastIndexOf('/'))
       if (!env[parentName]) {
         env[parentName] = oldOptions ? oldOptions[parentName] || {} : {}
       }
-      env[parentName][optionName.substr(optionName.lastIndexOf('/') + 1)] = options ? options[optionName] : null
+      env[parentName][optionName.substr(optionName.lastIndexOf('/') + 1)] = options
+        ? Utils.trim(optionName, options[optionName]) : null
     } else {
-      env[optionName] = options ? options[optionName] : null
+      env[optionName] = options ? Utils.trim(optionName, options[optionName]) : null
     }
   })
   return env

+ 8 - 0
src/utils/ObjectUtils.js

@@ -14,6 +14,8 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 // @flow
 
+import configLoader from './Config'
+
 class ObjectUtils {
   static flatten(object: any): any {
     let result = {}
@@ -70,6 +72,12 @@ class ObjectUtils {
     }
     await testLoop()
   }
+
+  static trim(fieldName: string, value: any): any {
+    let isPassword = configLoader.config.passwordFields.find(p => p === fieldName)
+      || fieldName.toLowerCase().indexOf('password') > -1
+    return typeof value === 'string' && !isPassword ? value.trim() : value
+  }
 }
 
 export default ObjectUtils