mirror of
https://github.com/meshtastic/firmware.git
synced 2025-02-26 22:33:24 +00:00
improve UTF-8 string handling in JSONValue (#6011)
Some checks failed
CI / setup (check) (push) Has been cancelled
CI / setup (esp32) (push) Has been cancelled
CI / setup (esp32c3) (push) Has been cancelled
CI / setup (esp32c6) (push) Has been cancelled
CI / setup (esp32s3) (push) Has been cancelled
CI / setup (nrf52840) (push) Has been cancelled
CI / setup (rp2040) (push) Has been cancelled
CI / setup (stm32) (push) Has been cancelled
CI / build-debian-src (push) Has been cancelled
CI / test-native (push) Has been cancelled
CI / docker-debian-amd64 (push) Has been cancelled
CI / docker-alpine-amd64 (push) Has been cancelled
CI / docker-debian-arm64 (push) Has been cancelled
CI / docker-debian-armv7 (push) Has been cancelled
Flawfinder Scan / Flawfinder (push) Has been cancelled
CI / check (push) Has been cancelled
CI / build-esp32 (push) Has been cancelled
CI / build-esp32-s3 (push) Has been cancelled
CI / build-esp32-c3 (push) Has been cancelled
CI / build-esp32-c6 (push) Has been cancelled
CI / build-nrf52 (push) Has been cancelled
CI / build-rpi2040 (push) Has been cancelled
CI / build-stm32 (push) Has been cancelled
CI / after-checks (push) Has been cancelled
CI / gather-artifacts (esp32) (push) Has been cancelled
CI / gather-artifacts (esp32c3) (push) Has been cancelled
CI / gather-artifacts (esp32c6) (push) Has been cancelled
CI / gather-artifacts (esp32s3) (push) Has been cancelled
CI / gather-artifacts (nrf52840) (push) Has been cancelled
CI / gather-artifacts (rp2040) (push) Has been cancelled
CI / gather-artifacts (stm32) (push) Has been cancelled
CI / release-artifacts (push) Has been cancelled
CI / release-firmware (esp32) (push) Has been cancelled
CI / release-firmware (esp32c3) (push) Has been cancelled
CI / release-firmware (esp32c6) (push) Has been cancelled
CI / release-firmware (esp32s3) (push) Has been cancelled
CI / release-firmware (nrf52840) (push) Has been cancelled
CI / release-firmware (rp2040) (push) Has been cancelled
CI / release-firmware (stm32) (push) Has been cancelled
Some checks failed
CI / setup (check) (push) Has been cancelled
CI / setup (esp32) (push) Has been cancelled
CI / setup (esp32c3) (push) Has been cancelled
CI / setup (esp32c6) (push) Has been cancelled
CI / setup (esp32s3) (push) Has been cancelled
CI / setup (nrf52840) (push) Has been cancelled
CI / setup (rp2040) (push) Has been cancelled
CI / setup (stm32) (push) Has been cancelled
CI / build-debian-src (push) Has been cancelled
CI / test-native (push) Has been cancelled
CI / docker-debian-amd64 (push) Has been cancelled
CI / docker-alpine-amd64 (push) Has been cancelled
CI / docker-debian-arm64 (push) Has been cancelled
CI / docker-debian-armv7 (push) Has been cancelled
Flawfinder Scan / Flawfinder (push) Has been cancelled
CI / check (push) Has been cancelled
CI / build-esp32 (push) Has been cancelled
CI / build-esp32-s3 (push) Has been cancelled
CI / build-esp32-c3 (push) Has been cancelled
CI / build-esp32-c6 (push) Has been cancelled
CI / build-nrf52 (push) Has been cancelled
CI / build-rpi2040 (push) Has been cancelled
CI / build-stm32 (push) Has been cancelled
CI / after-checks (push) Has been cancelled
CI / gather-artifacts (esp32) (push) Has been cancelled
CI / gather-artifacts (esp32c3) (push) Has been cancelled
CI / gather-artifacts (esp32c6) (push) Has been cancelled
CI / gather-artifacts (esp32s3) (push) Has been cancelled
CI / gather-artifacts (nrf52840) (push) Has been cancelled
CI / gather-artifacts (rp2040) (push) Has been cancelled
CI / gather-artifacts (stm32) (push) Has been cancelled
CI / release-artifacts (push) Has been cancelled
CI / release-firmware (esp32) (push) Has been cancelled
CI / release-firmware (esp32c3) (push) Has been cancelled
CI / release-firmware (esp32c6) (push) Has been cancelled
CI / release-firmware (esp32s3) (push) Has been cancelled
CI / release-firmware (nrf52840) (push) Has been cancelled
CI / release-firmware (rp2040) (push) Has been cancelled
CI / release-firmware (stm32) (push) Has been cancelled
```text feat(json): improve UTF-8 string handling in JSONValue - Add proper UTF-8 multi-byte character sequence handling - Add boundary checks for UTF-8 sequences - Keep original code structure and flow - Add detailed comments for UTF-8 processing logic This change improves the robustness of JSON string handling while maintaining compatibility with existing code.
This commit is contained in:
parent
4e8c4f0d55
commit
d70a9392af
@ -850,18 +850,26 @@ std::string JSONValue::StringifyString(const std::string &str)
|
|||||||
str_out += "\\r";
|
str_out += "\\r";
|
||||||
} else if (chr == '\t') {
|
} else if (chr == '\t') {
|
||||||
str_out += "\\t";
|
str_out += "\\t";
|
||||||
} else if (chr < ' ' || chr > 126) {
|
} else if (chr < 0x20 || chr == 0x7F) {
|
||||||
str_out += "\\u";
|
char buf[7];
|
||||||
for (int i = 0; i < 4; i++) {
|
snprintf(buf, sizeof(buf), "\\u%04x", chr);
|
||||||
int value = (chr >> 12) & 0xf;
|
str_out += buf;
|
||||||
if (value >= 0 && value <= 9)
|
} else if (chr < 0x80) {
|
||||||
str_out += (char)('0' + value);
|
str_out += chr;
|
||||||
else if (value >= 10 && value <= 15)
|
|
||||||
str_out += (char)('A' + (value - 10));
|
|
||||||
chr <<= 4;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
str_out += chr;
|
str_out += chr;
|
||||||
|
size_t remain = str.end() - iter - 1;
|
||||||
|
if ((chr & 0xE0) == 0xC0 && remain >= 1) {
|
||||||
|
++iter;
|
||||||
|
str_out += *iter;
|
||||||
|
} else if ((chr & 0xF0) == 0xE0 && remain >= 2) {
|
||||||
|
str_out += *(++iter);
|
||||||
|
str_out += *(++iter);
|
||||||
|
} else if ((chr & 0xF8) == 0xF0 && remain >= 3) {
|
||||||
|
str_out += *(++iter);
|
||||||
|
str_out += *(++iter);
|
||||||
|
str_out += *(++iter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
++iter;
|
++iter;
|
||||||
|
Loading…
Reference in New Issue
Block a user