mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 15:00:57 +03:00
Fix import null bytes error (#5036)
fix: sanitize null bytes in import data from SQLite
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
export function sanitizeNullBytes(obj: any): any {
|
||||
const stack = [obj]
|
||||
|
||||
while (stack.length) {
|
||||
const current = stack.pop()
|
||||
|
||||
if (Array.isArray(current)) {
|
||||
for (let i = 0; i < current.length; i++) {
|
||||
const val = current[i]
|
||||
if (typeof val === 'string') {
|
||||
// eslint-disable-next-line no-control-regex
|
||||
current[i] = val.replace(/\u0000/g, '')
|
||||
} else if (val && typeof val === 'object') {
|
||||
stack.push(val)
|
||||
}
|
||||
}
|
||||
} else if (current && typeof current === 'object') {
|
||||
for (const key in current) {
|
||||
if (!Object.hasOwnProperty.call(current, key)) continue
|
||||
const val = current[key]
|
||||
if (typeof val === 'string') {
|
||||
// eslint-disable-next-line no-control-regex
|
||||
current[key] = val.replace(/\u0000/g, '')
|
||||
} else if (val && typeof val === 'object') {
|
||||
stack.push(val)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return obj
|
||||
}
|
||||
Reference in New Issue
Block a user