Skip to content

Commit

Permalink
removed sanitizeData for now
Browse files Browse the repository at this point in the history
  • Loading branch information
pc committed Oct 2, 2019
1 parent 66d529a commit 4130f7b
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions utils/utilities.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const constants = require('./constants')
const sanitizer = require('sanitize')()
const emailPattern = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/

const respondBack = (attrs) => {
const {error, statusCode, body, headers, callback} = attrs
Expand All @@ -18,27 +19,27 @@ const respondBack = (attrs) => {
*/
const sanitizeData = (data) => {
// TODO:
if(typeof data == 'object'){
if(Arrays.isArray(data)){
//
} else {
data = data.map((v, k)=>{
// Don't sanitize email or username
// TODO: Use /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
// from https://stackoverflow.com/questions/46155/how-to-validate-an-email-address-in-javascript
if(k == 'username'){
if(/[\w\d.]+@[\w\d.]+\.\w+/.test(v)){
return "";
}
return v;
}
return sanitizeData(v)
})
}
} else if(typeof data == 'string'){
// TODO:
data = sanitizer.value(data, 'string')
}
// if(typeof data == 'object'){
// if(Arrays.isArray(data)){
// //
// } else {
// data = data.map((v, k)=>{
// // Don't sanitize email or username
// // TODO: Use /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
// // from https://stackoverflow.com/questions/46155/how-to-validate-an-email-address-in-javascript
// if(k == 'username'){
// if(emailPattern.test(v)){ // /[\w\d.]+@[\w\d.]+\.\w+/
// return "";
// }
// return v;
// }
// return sanitizeData(v)
// })
// }
// } else if(typeof data == 'string'){
// // TODO:
// data = sanitizer.value(data, 'string')
// }
return data
}

Expand Down

0 comments on commit 4130f7b

Please sign in to comment.