diff --git a/.github/workflows/test_coverage.yml b/.github/workflows/test_coverage.yml index e1b2676b..0e4cf82a 100644 --- a/.github/workflows/test_coverage.yml +++ b/.github/workflows/test_coverage.yml @@ -76,6 +76,7 @@ jobs: if: github.event_name == 'pull_request' uses: codecov/codecov-action@v4 with: + use_oidc: ${{ github.event.pull_request.head.repo.full_name == github.repository }} files: coverage.dat verbose: true fail_ci_if_error: true diff --git a/include/sonic/internal/arch/common/quote_common.h b/include/sonic/internal/arch/common/quote_common.h index a3edd693..31f4a05f 100644 --- a/include/sonic/internal/arch/common/quote_common.h +++ b/include/sonic/internal/arch/common/quote_common.h @@ -157,17 +157,17 @@ sonic_static_inline void DoEscape(const char*& src, char*& dst, size_t& nb) { // Not enough bytes for a 4-byte emoji, handle as raw char or error *dst++ = *src++; nb--; - continue; + } else { + // TODO: validate the utf8? + uint32_t unicode = (src[0] & 0x07) << 18 | (src[1] & 0x3f) << 12 | + (src[2] & 0x3f) << 6 | (src[3] & 0x3f); + unicode -= 0x10000; + writeHex(0xD800 | ((unicode >> 10) & 0x3FF), + dst); + writeHex(0xDC00 | (unicode & 0x3FF), dst); + src += 4; + nb -= 4; } - // TODO: validate the utf8? - uint32_t unicode = (src[0] & 0x07) << 18 | (src[1] & 0x3f) << 12 | - (src[2] & 0x3f) << 6 | (src[3] & 0x3f); - unicode -= 0x10000; - writeHex(0xD800 | ((unicode >> 10) & 0x3FF), - dst); - writeHex(0xDC00 | (unicode & 0x3FF), dst); - src += 4; - nb -= 4; } } diff --git a/tests/quote_test.cpp b/tests/quote_test.cpp index 6cfb0db0..c8c818eb 100644 --- a/tests/quote_test.cpp +++ b/tests/quote_test.cpp @@ -40,6 +40,13 @@ void TestQuote(const std::string& input, const std::string& expect) { EXPECT_STREQ(buf.get(), expect.data()); } +void TestQuoteEscapeEmoji(const char* input, size_t n, + const std::string& expect) { + auto buf = std::unique_ptr(new char[(n + 2) * 12 + 32]); + char* end = Quote(input, n, buf.get()); + EXPECT_EQ(std::string(buf.get(), end - buf.get()), expect); +} + TEST(Quote, Normal) { std::vector tests = { {"", "\"\""}, @@ -73,4 +80,11 @@ TEST(Quote, DiffSize) { } } +TEST(Quote, EscapeEmojiStopsAtEndOfInvalidTail) { + const char input[] = {'\xfe', '\xff', '\xff'}; + const char expect[] = {'"', '\xfe', '\xff', '\xff', '"'}; + TestQuoteEscapeEmoji(input, sizeof(input), + std::string(expect, sizeof(expect))); +} + } // namespace