mirror of https://github.com/waku-org/js-waku.git
Fixed `payloadAsUtf8` returning garbage on utf-8 non-ascii characters
This commit is contained in:
parent
159a352088
commit
1f692f1683
|
@ -15,6 +15,9 @@ 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;
|
||||
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.
|
||||
|
||||
## [0.9.0] - 2021-07-26
|
||||
|
||||
### Changed
|
||||
|
|
|
@ -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 Array.from(this.proto.payload)
|
||||
.map((char) => {
|
||||
return String.fromCharCode(char);
|
||||
})
|
||||
.join('');
|
||||
return Buffer.from(this.proto.payload).toString('utf-8');
|
||||
}
|
||||
|
||||
get payload(): Uint8Array | undefined {
|
||||
|
|
Loading…
Reference in New Issue