mirror of https://github.com/waku-org/js-waku.git
Merge pull request #249 from status-im/utf8
Fixed `payloadAsUtf8` returning garbage on utf-8 non-ascii characters
This commit is contained in:
commit
a3b7e37d8b
|
@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
- **Breaking**: Removed `DefaultContentTopic` as developers must choose a content topic for their app;
|
- **Breaking**: Removed `DefaultContentTopic` as developers must choose a content topic for their app;
|
||||||
recommendations for content topic can be found at https://rfc.vac.dev/spec/23/.
|
recommendations for content topic can be found at https://rfc.vac.dev/spec/23/.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- `WakuMessage.payloadAsUtf8` returning garbage on utf-8 non-ascii characters.
|
||||||
|
- `ChatMessage.payloadAsUtf8` returning garbage on utf-8 non-ascii characters.
|
||||||
|
|
||||||
## [0.9.0] - 2021-07-26
|
## [0.9.0] - 2021-07-26
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
|
@ -60,10 +60,6 @@ export class ChatMessage {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
return Array.from(this.proto.payload)
|
return Buffer.from(this.proto.payload).toString('utf-8');
|
||||||
.map((char) => {
|
|
||||||
return String.fromCharCode(char);
|
|
||||||
})
|
|
||||||
.join('');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,4 +119,16 @@ describe('Waku Message: Browser & Node', function () {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Waku message round trip utf-8 including emojis', async function () {
|
||||||
|
const messageText = '😁🤣🥧🤦👩🎓';
|
||||||
|
const wakuMessage = await WakuMessage.fromUtf8String(
|
||||||
|
messageText,
|
||||||
|
TestContentTopic
|
||||||
|
);
|
||||||
|
|
||||||
|
const decodedText = wakuMessage.payloadAsUtf8;
|
||||||
|
|
||||||
|
expect(decodedText).to.eq(messageText);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -205,11 +205,7 @@ export class WakuMessage {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
return Array.from(this.proto.payload)
|
return Buffer.from(this.proto.payload).toString('utf-8');
|
||||||
.map((char) => {
|
|
||||||
return String.fromCharCode(char);
|
|
||||||
})
|
|
||||||
.join('');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get payload(): Uint8Array | undefined {
|
get payload(): Uint8Array | undefined {
|
||||||
|
|
Loading…
Reference in New Issue