Fixed deserialization of \u0000 (issue #1646)

This commit is contained in:
Benoit Blanchon
2021-08-31 13:58:27 +02:00
parent 669bad27d4
commit 956e4a7cbb
4 changed files with 41 additions and 10 deletions

View File

@ -13,14 +13,14 @@ template <typename TStringBuilder>
inline void encodeCodepoint(uint32_t codepoint32, TStringBuilder& str) {
// this function was optimize for code size on AVR
// a buffer to store the string in reverse
char buf[5];
char* p = buf;
*(p++) = 0;
if (codepoint32 < 0x80) {
*(p++) = char((codepoint32));
str.append(char(codepoint32));
} else {
// a buffer to store the string in reverse
char buf[5];
char* p = buf;
*(p++) = 0;
*(p++) = char((codepoint32 | 0x80) & 0xBF);
uint16_t codepoint16 = uint16_t(codepoint32 >> 6);
if (codepoint16 < 0x20) { // 0x800
@ -36,10 +36,10 @@ inline void encodeCodepoint(uint32_t codepoint32, TStringBuilder& str) {
*(p++) = char(codepoint16 | 0xF0);
}
}
}
while (*(--p)) {
str.append(*p);
while (*(--p)) {
str.append(*p);
}
}
}
} // namespace Utf8