Skip to content

Commit

Permalink
Fix: GetOnDemand forgot copying " for parseStringInplace when
Browse files Browse the repository at this point in the history
key is escaped string.
  • Loading branch information
xiegx94 committed Mar 21, 2024
1 parent 4250a05 commit e24763b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion include/sonic/internal/arch/simd_skip.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ class SkipScanner {
// parse escaped key
kbuf.resize(sn + 32);
uint8_t *nsrc = &kbuf[0];
std::memcpy(nsrc, sp, sn);

// parseStringInplace need `"` as the end
std::memcpy(nsrc, sp, sn + 1);
sn = parseStringInplace(nsrc, err);
if (err) {
pos = (sp - data) + (nsrc - &kbuf[0]);
Expand Down
11 changes: 10 additions & 1 deletion tests/skip_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ TEST(GetOnDemand, SuccessEscapeCharacters) {
R"("\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\")");
TestGetOnDemand(R"({"a":"\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\""})", {"a"},
R"("\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"")");
TestGetOnDemand(R"({"\"a\"":"\n\tHello,\nworld!\n"})", {"\"a\""},
R"("\n\tHello,\nworld!\n")");
TestGetOnDemand(R"({"123456789012345\"123":"sse_string",
"1234567890123456789012345678901\"123":"avx2_string",
"obj\n\t\\":{"name\\\\\\\\":"string\\\\"},
"array\"\t\n\b\r":["\n\tHello,\nworld!\n",
"{\" / \b \f \n \r \t } [景] 测试中文 😀")],
"\"a\"":"\n\tHello,\nworld!\n"})",
{"\"a\""}, R"("\n\tHello,\nworld!\n")");
}

TEST(GetOnDemand, Failed) {
Expand All @@ -93,4 +102,4 @@ TEST(GetOnDemand, Failed) {

TestGetOnDemandFailed(R"("\")", {}, ParseResult(kParseErrorInvalidChar, 3));
}
} // namespace
} // namespace

0 comments on commit e24763b

Please sign in to comment.