Skip to content

Commit 5b17f76

Browse files
authored
Merge pull request #396 from permaweb/jfrain99/weavedrive-utf8
fix(weavedrive): store headers as utf8 encoded
2 parents d12b436 + 80e512e commit 5b17f76

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

extensions/weavedrive/src/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ module.exports = function weaveDrive(mod, FS) {
105105

106106
var bytesLength = result.length;
107107

108-
var node = FS.createDataFile('/', 'block/' + id, result, true, false);
108+
var node = FS.createDataFile('/', 'block/' + id, Buffer.from(result, 'utf-8'), true, false);
109109

110110
var stream = FS.open('/block/' + id, 'r');
111111
return stream;
@@ -135,7 +135,7 @@ module.exports = function weaveDrive(mod, FS) {
135135
//.then(x => (console.error(x), x))
136136
.then(x => JSON.stringify(x));
137137

138-
var node = FS.createDataFile('/', 'tx/' + id, result, true, false);
138+
var node = FS.createDataFile('/', 'tx/' + id, Buffer.from(result, 'utf-8'), true, false);
139139
var stream = FS.open('/tx/' + id, 'r');
140140
return stream;
141141
},
@@ -220,7 +220,7 @@ module.exports = function weaveDrive(mod, FS) {
220220
if (result === 'No results') {
221221
return result
222222
}
223-
FS.createDataFile('/', 'tx2/' + id, result, true, false);
223+
FS.createDataFile('/', 'tx2/' + id, Buffer.from(result, 'utf-8'), true, false);
224224
var stream = FS.open('/tx2/' + id, 'r');
225225

226226
return stream;

extensions/weavedrive/test/index.test.js

+18
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,24 @@ return result
356356
assert.equal(data.block.height, 1290333)
357357
})
358358

359+
test('data item with chinese characters', async () => {
360+
const chineseCharacterTx = 'Xg82mcAfQNgJetk_kSKqMkwYDfoMJLGw8fdheU3evWk'
361+
const handle = await AoLoader(wasm, options)
362+
const result = await handle(memory, {
363+
...Msg,
364+
Data: `
365+
local data = require('WeaveDrive').getDataItem('${chineseCharacterTx}')
366+
local json = require('json')
367+
local decoded = json.decode(data)
368+
return data
369+
`
370+
}, { Process, Module })
371+
memory = result.Memory
372+
const data = JSON.parse(result.Output.data)
373+
const description = data.tags.find(tag => tag.name === 'Description')?.value
374+
assert.equal(description, "Smartweave是不是要转到AO了?\n本文档介绍原子资产SmartWeave合约的标准接口。原子资产是SmartWeave合约及其在发布到Arweave的同一事务中初始化的数据。SmartWeave合约和数据共享一个交易ID。")
375+
})
376+
359377
test('read data item tx, no result', async () => {
360378
const handle = await AoLoader(wasm, options)
361379
const result = await handle(memory, {

0 commit comments

Comments
 (0)