diff options
author | Anand Thakker <anandthakker@users.noreply.github.com> | 2018-06-06 11:26:08 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-06 11:26:08 -0400 |
commit | 2da57bd1576c99ff4305cab7b6ad8c1a39ac2fa7 (patch) | |
tree | 5d2dfb87e69f0354d47a94acf54af40009932a04 /test/style | |
parent | 6eee8729554ed778491c52bda46cdcbec61b9c95 (diff) | |
download | qtlocation-mapboxgl-2da57bd1576c99ff4305cab7b6ad8c1a39ac2fa7.tar.gz |
[core] Fix crash due to mixing legacy filters and expressions (#12065)
* Fix crash due to mixing legacy filters and expressions
In some cases, (invalid) nested filters that used a mix of legacy filter
syntax and expression syntax caused a crash due to a failure to
propagate parsing errors from deeper within the filter expression.
These errors went undetected in part because these conversion functions
returned unique_ptr<Expression> values (or vectors thereof), using
{nullptr} to represent a parsing error, but the core expression classes
expect unique_ptr<Expression> that are never null.
This changes over to using expression::ParseResult (aka
optional<unique_ptr<Expression>>), to represent conversion failure
the same way we do in the rest of the expression system.
* Fix clang 3.8 / gcc 4.9 issue
Diffstat (limited to 'test/style')
-rw-r--r-- | test/style/filter.test.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/test/style/filter.test.cpp b/test/style/filter.test.cpp index c59a73eab1..c8f1d3b808 100644 --- a/test/style/filter.test.cpp +++ b/test/style/filter.test.cpp @@ -3,6 +3,11 @@ #include <mbgl/util/geometry.hpp> #include <mbgl/test/stub_geometry_tile_feature.hpp> +#include <mbgl/util/rapidjson.hpp> +#include <rapidjson/writer.h> +#include <rapidjson/stringbuffer.h> +#include <mbgl/style/conversion/stringify.hpp> + #include <mbgl/style/filter.hpp> #include <mbgl/style/conversion/json.hpp> #include <mbgl/style/conversion/filter.hpp> @@ -176,6 +181,13 @@ TEST(Filter, LegacyProperty) { ASSERT_FALSE(filter("[\"==\", \"two\", 4]", {{"two", std::string("2")}})); } +TEST(Filter, ExpressionLegacyMix) { + conversion::Error error; + optional<Filter> filter = conversion::convertJSON<Filter>(R"(["any", ["all", ["==", ["geometry-type"], "LineString"]], ["==", "x", 1]])", error); + EXPECT_FALSE(bool(filter)); + EXPECT_TRUE(error.message.size() > 0); +} + TEST(Filter, ZoomExpressionNested) { ASSERT_TRUE(filter(R"(["==", ["get", "two"], ["zoom"]])", {{"two", int64_t(2)}}, {}, FeatureType::Point, {}, 2.0f)); ASSERT_FALSE(filter(R"(["==", ["get", "two"], ["+", ["zoom"], 1]])", {{"two", int64_t(2)}}, {}, FeatureType::Point, {}, 2.0f)); |