Fixed `payloadAsUtf8` returning garbage on utf-8 non-ascii characters

This commit is contained in:
Franck Royer 2021-08-02 09:51:37 +10:00
parent 159a352088
commit 1f692f1683
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
3 changed files with 16 additions and 5 deletions

View File

@ -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

View File

@ -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);
});
});

View File

@ -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 {