You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
consttestDB=newDexie('testDB')testDB.version(1).stores({testTable: '++id'})// generate some test record and insert itconstinsertTestData=async()=>{console.log('start insert test data')// const testPattern = 'Lets speak English\n' // English// const testPattern = '日本語を話しましょう\n' // JapaneseconsttestPattern='让我们说中文\n'// Chineseconstdata=Array(1000).fill(0).map(()=>({content: testPattern.repeat(1000)}))awaittestDB.table('testTable').bulkAdd(data)console.log('insert test data done',data.length,awaittestDB.table('testTable').count())}// check if there's �� in content (this should not happen)constcheckTestData=async()=>{console.log('start check test data')constdata=awaittestDB.table('testTable').toArray()constcorruptedData=data.filter(record=>record.content.includes("��"))if(corruptedData.length>0){console.error('check test data failed, corrupt count: ',corruptedData.length)returnfalse}console.log('check test data done, no corrupt',data.length)}constexportAndImportDb=async()=>{// export and import the db// export works OKconsole.log('start export db')constdata=awaitexportDB(testDB,{prettyJson: false})console.log('export db done')// proof that export is okconststringData=awaitdata.text()if(stringData.includes('��')){console.warn('exported data should not contain ��')}// !!! this is where the bug happensconsole.log('start import db')awaitimportDB(data,{clearTablesBeforeImport: true})console.log('import db done')}testDB.table('testTable').clear().then(()=>insertTestData()).then(()=>checkTestData())// this should success (no corrupt).then(()=>exportAndImportDb())// this should cause the data to be corrupt.then(()=>checkTestData())// this should fail (corrupt data)
The text was updated successfully, but these errors were encountered:
cha0sCat
changed the title
Bug(dexie-export-import): importDb can cause data corrupt
Bug(dexie-export-import): importDb data corrupt on non-ASCII string
Dec 4, 2024
exportDB works great.
importDB can cause data corruption on non-ascii characters.
For example, if we save '让我们说中文' as string, export & import can make some of the records become '让我们��中文'
Here's the reproducible code:
https://jsfiddle.net/j58xz679/10/
The text was updated successfully, but these errors were encountered: