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
9 changes: 7 additions & 2 deletions Firestore/core/src/bundle/bundle_serializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ void DecodeCollectionSource(JsonReader& reader,
const json& from_json,
ResourcePath& parent,
std::string& group) {
if (!from_json.is_array()) {
reader.Fail("'from' clause is not an array as expected.");
return;
}
const auto& from = from_json.get_ref<const std::vector<json>&>();
if (from.size() != 1) {
reader.Fail(
Expand Down Expand Up @@ -275,8 +279,9 @@ int32_t DecodeLimit(JsonReader& reader, const json& query) {
if (limit_object.is_number_integer()) {
return limit_object.get<int32_t>();
} else if (limit_object.is_object()) {
if (limit_object.at("value").is_number_integer()) {
return limit_object.at("value").get<int32_t>();
auto value = limit_object.find("value");
if (value != limit_object.end() && value->is_number_integer()) {
return value->get<int32_t>();
}
}
reader.Fail("'limit' is not encoded as a valid integer");
Expand Down
18 changes: 18 additions & 0 deletions Firestore/core/test/unit/bundle/bundle_serializer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,24 @@ TEST_F(BundleSerializerTest, DecodeQueriesFromOtherProjectsFails) {
}
}

TEST_F(BundleSerializerTest, DecodeFromClauseWithWrongTypeFails) {
std::string json_string = NamedQueryJsonString(testutil::Query("colls"));
json parsed = Parse(json_string);
parsed["bundledQuery"]["structuredQuery"]["from"] = "colls";
JsonReader reader;
bundle_serializer.DecodeNamedQuery(reader, parsed);
EXPECT_NOT_OK(reader.status());
}

TEST_F(BundleSerializerTest, DecodeLimitObjectWithoutValueFails) {
std::string json_string = NamedQueryJsonString(testutil::Query("colls"));
json parsed = Parse(json_string);
parsed["bundledQuery"]["structuredQuery"]["limit"] = json::object();
JsonReader reader;
bundle_serializer.DecodeNamedQuery(reader, parsed);
EXPECT_NOT_OK(reader.status());
}

TEST_F(BundleSerializerTest, DecodesCollectionGroupQuery) {
core::Query original = testutil::CollectionGroupQuery("bundles/docs/colls");
VerifyNamedQueryRoundtrip(original);
Expand Down
Loading