diff options
author | Sam Matthews <matthews.sam@gmail.com> | 2016-10-03 10:08:17 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-10-03 10:08:17 -0700 |
commit | 280fd8c28ed670418954e0a6e2f26292419103d6 (patch) | |
tree | 78d5978251419d5b3f89f208ede4a2f9c4b0ee89 | |
parent | 4bbdb448fd619ae55a9366556923a5d1aaf8cee7 (diff) | |
download | qtlocation-mapboxgl-280fd8c28ed670418954e0a6e2f26292419103d6.tar.gz |
[core] Preserve non-access_token query parameters in canonicalizeTileURL
-rw-r--r-- | src/mbgl/util/mapbox.cpp | 11 | ||||
-rw-r--r-- | test/util/mapbox.test.cpp | 9 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/mbgl/util/mapbox.cpp b/src/mbgl/util/mapbox.cpp index 32194754ec..9cf250f7a3 100644 --- a/src/mbgl/util/mapbox.cpp +++ b/src/mbgl/util/mapbox.cpp @@ -5,6 +5,7 @@ #include <stdexcept> #include <vector> #include <iostream> +#include <regex> namespace { @@ -191,6 +192,16 @@ std::string canonicalizeTileURL(const std::string& url, SourceType type, uint16_ } result += "." + extension; + + // get the query and remove access_token, if more parameters exist, add them to the final result + if (queryIdx != url.length()) { + const auto query = url.substr(queryIdx + 1); + std::regex re ("&?access_token=([^&]*)"); + std::string replace = std::regex_replace(query, re, ""); + std::string subQuery = (replace.find("&") == 0) ? replace.substr(1, replace.length()) : replace; + if (subQuery.length() > 0) result += "?" + subQuery; + } + return result; } diff --git a/test/util/mapbox.test.cpp b/test/util/mapbox.test.cpp index b559c3a947..04c9808ed3 100644 --- a/test/util/mapbox.test.cpp +++ b/test/util/mapbox.test.cpp @@ -142,6 +142,15 @@ TEST(Mapbox, CanonicalURL) { "mapbox://tiles/a.b,c.d/{z}/{x}/{y}.vector.pbf", mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/a.b,c.d/{z}/{x}/{y}.vector.pbf?access_token=key", SourceType::Vector, 512)); EXPECT_EQ( + "mapbox://tiles/a.b/{z}/{x}/{y}.vector.pbf?custom=parameter", + mbgl::util::mapbox::canonicalizeTileURL("http://a.tiles.mapbox.com/v4/a.b/{z}/{x}/{y}.vector.pbf?access_token=key&custom=parameter", SourceType::Vector, 512)); + EXPECT_EQ( + "mapbox://tiles/a.b/{z}/{x}/{y}.vector.pbf?custom=parameter", + mbgl::util::mapbox::canonicalizeTileURL("http://a.tiles.mapbox.com/v4/a.b/{z}/{x}/{y}.vector.pbf?custom=parameter&access_token=key", SourceType::Vector, 512)); + EXPECT_EQ( + "mapbox://tiles/a.b/{z}/{x}/{y}.vector.pbf?custom=parameter&second=param", + mbgl::util::mapbox::canonicalizeTileURL("http://a.tiles.mapbox.com/v4/a.b/{z}/{x}/{y}.vector.pbf?custom=parameter&access_token=key&second=param", SourceType::Vector, 512)); + EXPECT_EQ( "mapbox://tiles/a.b/{z}/{x}/{y}{ratio}.jpg", mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/a.b/{z}/{x}/{y}.jpg?access_token=key", SourceType::Raster, 256)); EXPECT_EQ( |