Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion include/sonic/internal/arch/simd_skip.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <cstdint>
#include <functional>
#include <memory>
#include <optional>
#include <vector>

Expand All @@ -29,7 +30,7 @@

#include INCLUDE_ARCH_FILE(skip.h)

#include <sonic/dom/parser.h>
#include "sonic/dom/parser.h"

namespace sonic_json {
namespace internal {
Expand Down Expand Up @@ -346,7 +347,16 @@ class SkipScanner2 {
}

sonic_force_inline uint8_t peek() {
if (sonic_unlikely(pos_ >= len_)) {
setError(SonicError::kParseErrorEof);
return 0;
}
auto peek = scanner_.SkipSpaceSafe(data_, pos_, len_);
// SkipSpaceSafe returns the last space if no token remains.
if (sonic_unlikely(pos_ == len_ && IsSpace(peek))) {
setError(SonicError::kParseErrorEof);
return 0;
}
pos_ -= 1;
return peek;
}
Expand Down
1 change: 0 additions & 1 deletion include/sonic/internal/itoa.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ sonic_force_inline char *Utoa_1_8(char *out, uint32_t val) {
lz = val < 10;
Copy2Digs(out, &kDigits[val * 2 + lz]);
return out + 2 - lz;
;
} else if (val < 10000) { // 3 ~ 4 digits
hi = val / 100;
lo = val % 100;
Expand Down
16 changes: 16 additions & 0 deletions tests/jsonpath_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,22 @@ TEST(JsonPath, JsonInfiniteLoop3) {
EXPECT_EQ(std::get<0>(got), "");
}

TEST(JsonPath, IncompleteArrayIndex) {
auto got = GetByJsonPathOnDemand("[8", "$[0]");
EXPECT_EQ(std::get<1>(got), kParseErrorEof);
EXPECT_EQ(std::get<0>(got), "8");

TestFail("[8 ", "$[0]");
TestFail("[8,", "$[0]");
TestFail("[8, ", "$[0]");
TestFail("[8,9", "$[0]");
TestFail("[[8", "$[0][0]");

got = GetByJsonPathOnDemand("[8]", "$[0]");
EXPECT_EQ(std::get<1>(got), kErrorNone);
EXPECT_EQ(std::get<0>(got), "8");
}

TEST(JsonPath, JsonTuple) {
auto json = R"({a:1, b:2c})";
auto got = GetByJsonPathOnDemand(json, "$.b");
Expand Down