(target: T, source: Record<string, unknown>)
| 12 | * Use this instead of Object.assign() when the source may contain user-controlled data. |
| 13 | */ |
| 14 | export function safeAssign<T extends object>(target: T, source: Record<string, unknown>): T { |
| 15 | if (!source || typeof source !== 'object') { |
| 16 | return target |
| 17 | } |
| 18 | |
| 19 | for (const key of Object.keys(source)) { |
| 20 | if (isSafeKey(key)) { |
| 21 | ;(target as Record<string, unknown>)[key] = source[key] |
| 22 | } |
| 23 | } |
| 24 | return target |
| 25 | } |
no test coverage detected