Closed direc85 closed 1 year ago
Thanks! the patch looks good. Could you write a test?
First I tried to append the test to the function above, but I couldn't replicate the behavior. I then decided to take the gist of the erroneous code and make a new test out of it.
When I revert the fix, the test fails with
---- test_qjsonobject_utf8 stdout ----
thread 'test_qjsonobject_utf8' panicked at 'assertion failed: `(left == right)`
left: `"{\"ð\u{9f}¦\u{80}\":1}"`,
right: `"{\"🦀\":1}"`', qttypes/src/lib.rs:1784:5
Thank you!
During developing Whisperfish, I noticed that pushing emojis into QJsonObject and reading them back didn't work correctly.
Code:
Output before:
Output after:
The cause was as I suspected: Usage of
QString::fromLatin1(const char *str, qsizetype size)
doesn't handle UTF-8 encoding correctly, but usingQString::fromUtf8(const char8_t *str, qsizetype size)
is able to handle it.