(obj: any)
| 2 | import { isIPv4, isIPv6, isValidIPAddress } from './ipValidation' |
| 3 | |
| 4 | export function sanitizeNullBytes(obj: any): any { |
| 5 | const stack = [obj] |
| 6 | |
| 7 | while (stack.length) { |
| 8 | const current = stack.pop() |
| 9 | |
| 10 | if (Array.isArray(current)) { |
| 11 | for (let i = 0; i < current.length; i++) { |
| 12 | const val = current[i] |
| 13 | if (typeof val === 'string') { |
| 14 | // eslint-disable-next-line no-control-regex |
| 15 | current[i] = val.replace(/\u0000/g, '') |
| 16 | } else if (val && typeof val === 'object') { |
| 17 | stack.push(val) |
| 18 | } |
| 19 | } |
| 20 | } else if (current && typeof current === 'object') { |
| 21 | for (const key in current) { |
| 22 | if (!Object.hasOwnProperty.call(current, key)) continue |
| 23 | const val = current[key] |
| 24 | if (typeof val === 'string') { |
| 25 | // eslint-disable-next-line no-control-regex |
| 26 | current[key] = val.replace(/\u0000/g, '') |
| 27 | } else if (val && typeof val === 'object') { |
| 28 | stack.push(val) |
| 29 | } |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | return obj |
| 35 | } |
| 36 | |
| 37 | export function sanitizeUser(user: Partial<User>) { |
| 38 | delete user.credential |
no test coverage detected