summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mbgl/style/conversion/filter.cpp7
-rw-r--r--test/style/filter.test.cpp7
2 files changed, 13 insertions, 1 deletions
diff --git a/src/mbgl/style/conversion/filter.cpp b/src/mbgl/style/conversion/filter.cpp
index 4e8d9c48e5..1b77985322 100644
--- a/src/mbgl/style/conversion/filter.cpp
+++ b/src/mbgl/style/conversion/filter.cpp
@@ -195,11 +195,16 @@ ParseResult convertLegacyFilter(const Convertible& values, Error& error) {
return {std::make_unique<Literal>(true)};
}
+ if (!isArray(values) || arrayLength(values) == 0) {
+ error.message = "filter value must be a non empty array";
+ return nullopt;
+ }
+
optional<std::string> op = toString(arrayMember(values, 0));
if (!op) {
error.message = "filter operator must be a string";
- return {};
+ return nullopt;
} else if (arrayLength(values) <= 1) {
return {std::make_unique<Literal>(*op != "any")};
} else {
diff --git a/test/style/filter.test.cpp b/test/style/filter.test.cpp
index 40219108bb..f3f5b52141 100644
--- a/test/style/filter.test.cpp
+++ b/test/style/filter.test.cpp
@@ -255,3 +255,10 @@ TEST(Filter, Internal) {
TEST(Filter, Short) {
filter(R"(["==", ["id"], "foo"])");
}
+
+TEST(Filter, LegacyExpressionInvalidType) {
+ const JSValue value("string");
+ conversion::Error error;
+ optional<Filter> result = conversion::convert<Filter>(conversion::Convertible(&value), error);
+ EXPECT_FALSE(result);
+}