Merge pull request #249 from status-im/utf8

Fixed `payloadAsUtf8` returning garbage on utf-8 non-ascii characters
This commit is contained in:
Franck Royer 2021-08-02 10:44:45 +10:00 committed by GitHub
commit a3b7e37d8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 10 deletions

View File

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

View File

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

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 '';
} }
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 {