Fix import null bytes error (#5036)
fix: sanitize null bytes in import data from SQLite
This commit is contained in:
parent
141c49013a
commit
9e743e4aa1
|
|
@ -26,6 +26,7 @@ import marketplacesService from '../marketplaces'
|
||||||
import toolsService from '../tools'
|
import toolsService from '../tools'
|
||||||
import variableService from '../variables'
|
import variableService from '../variables'
|
||||||
import { Platform } from '../../Interface'
|
import { Platform } from '../../Interface'
|
||||||
|
import { sanitizeNullBytes } from '../../utils/sanitize.util'
|
||||||
|
|
||||||
type ExportInput = {
|
type ExportInput = {
|
||||||
agentflow: boolean
|
agentflow: boolean
|
||||||
|
|
@ -753,6 +754,8 @@ const importData = async (importData: ExportData, orgId: string, activeWorkspace
|
||||||
importData = await replaceDuplicateIdsForVariable(queryRunner, importData, importData.Variable)
|
importData = await replaceDuplicateIdsForVariable(queryRunner, importData, importData.Variable)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
importData = sanitizeNullBytes(importData)
|
||||||
|
|
||||||
await queryRunner.startTransaction()
|
await queryRunner.startTransaction()
|
||||||
|
|
||||||
if (importData.AgentFlow.length > 0) await queryRunner.manager.save(ChatFlow, importData.AgentFlow)
|
if (importData.AgentFlow.length > 0) await queryRunner.manager.save(ChatFlow, importData.AgentFlow)
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue