diff --git a/CHANGELOG.md b/CHANGELOG.md index e5d2da8846..22962ff584 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/lib/waku_message/index.browser.spec.ts b/src/lib/waku_message/index.browser.spec.ts index 0b8bf5c540..5cc9bd4f40 100644 --- a/src/lib/waku_message/index.browser.spec.ts +++ b/src/lib/waku_message/index.browser.spec.ts @@ -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); + }); }); diff --git a/src/lib/waku_message/index.ts b/src/lib/waku_message/index.ts index 1f3289fcc9..57b3ec8f65 100644 --- a/src/lib/waku_message/index.ts +++ b/src/lib/waku_message/index.ts @@ -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 {