From 6e830725de430de6aa573955769916edcb878e33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Tue, 19 Jul 2016 16:01:24 +0200 Subject: [android] #5725 - Cherry picking 559f3a654b976d41d0f3db3fa958ebcda3e97b1c --- src/mbgl/util/mapbox.cpp | 8 ++++++ test/util/mapbox.cpp | 72 ++++++++++++++++++++++++++++++++++++------------ 2 files changed, 62 insertions(+), 18 deletions(-) diff --git a/src/mbgl/util/mapbox.cpp b/src/mbgl/util/mapbox.cpp index 41959563f0..15c369a995 100644 --- a/src/mbgl/util/mapbox.cpp +++ b/src/mbgl/util/mapbox.cpp @@ -82,10 +82,18 @@ std::string normalizeSpriteURL(const std::string& url, const std::string& access std::string id, extension; if (isDraft) { size_t index = pathname[3].find_first_of("@."); + if (index == std::string::npos) { + Log::Error(Event::ParseStyle, "Invalid sprite URL"); + return url; + } id = pathname[2]; extension = pathname[3].substr(index); } else { size_t index = pathname[2].find_first_of("@."); + if (index == std::string::npos) { + Log::Error(Event::ParseStyle, "Invalid sprite URL"); + return url; + } id = pathname[2].substr(0, index); extension = pathname[2].substr(index); } diff --git a/test/util/mapbox.cpp b/test/util/mapbox.cpp index e5da25991d..9341b695f3 100644 --- a/test/util/mapbox.cpp +++ b/test/util/mapbox.cpp @@ -7,34 +7,70 @@ using namespace mbgl; -// TODO: correct all EXPECT_EQ(actual, expected) to EXPECT_EQ(expected, actual) - TEST(Mapbox, SourceURL) { - EXPECT_EQ(mbgl::util::mapbox::normalizeSourceURL("mapbox://user.map", "key"), "https://api.mapbox.com/v4/user.map.json?access_token=key&secure"); - EXPECT_EQ(mbgl::util::mapbox::normalizeSourceURL("mapbox://user.map", "token"), "https://api.mapbox.com/v4/user.map.json?access_token=token&secure"); - EXPECT_THROW(mbgl::util::mapbox::normalizeSourceURL("mapbox://user.map", ""), std::runtime_error); + EXPECT_EQ( + "https://api.mapbox.com/v4/user.map.json?access_token=key&secure", + mbgl::util::mapbox::normalizeSourceURL("mapbox://user.map", "key")); + EXPECT_EQ( + "http://path", + mbgl::util::mapbox::normalizeSourceURL("http://path", "key")); + EXPECT_THROW( + mbgl::util::mapbox::normalizeSourceURL("mapbox://user.map", ""), + std::runtime_error); } TEST(Mapbox, GlyphsURL) { - EXPECT_EQ(mbgl::util::mapbox::normalizeGlyphsURL("mapbox://fonts/boxmap/Comic%20Sans/0-255.pbf", "key"), "https://api.mapbox.com/fonts/v1/boxmap/Comic%20Sans/0-255.pbf?access_token=key"); - EXPECT_EQ(mbgl::util::mapbox::normalizeGlyphsURL("mapbox://fonts/boxmap/{fontstack}/{range}.pbf", "key"), "https://api.mapbox.com/fonts/v1/boxmap/{fontstack}/{range}.pbf?access_token=key"); - EXPECT_EQ(mbgl::util::mapbox::normalizeGlyphsURL("http://path", "key"), "http://path"); - EXPECT_EQ(mbgl::util::mapbox::normalizeGlyphsURL("mapbox://path", "key"), "mapbox://path"); + EXPECT_EQ( + "https://api.mapbox.com/fonts/v1/boxmap/Comic%20Sans/0-255.pbf?access_token=key", + mbgl::util::mapbox::normalizeGlyphsURL("mapbox://fonts/boxmap/Comic%20Sans/0-255.pbf", "key")); + EXPECT_EQ( + "https://api.mapbox.com/fonts/v1/boxmap/{fontstack}/{range}.pbf?access_token=key", + mbgl::util::mapbox::normalizeGlyphsURL("mapbox://fonts/boxmap/{fontstack}/{range}.pbf", "key")); + EXPECT_EQ( + "http://path", + mbgl::util::mapbox::normalizeGlyphsURL("http://path", "key")); + EXPECT_EQ( + "mapbox://path", + mbgl::util::mapbox::normalizeGlyphsURL("mapbox://path", "key")); } TEST(Mapbox, StyleURL) { - EXPECT_EQ(mbgl::util::mapbox::normalizeStyleURL("mapbox://foo", "key"), "mapbox://foo"); - EXPECT_EQ(mbgl::util::mapbox::normalizeStyleURL("mapbox://styles/user/style", "key"), "https://api.mapbox.com/styles/v1/user/style?access_token=key"); - EXPECT_EQ(mbgl::util::mapbox::normalizeStyleURL("mapbox://styles/user/style/draft", "key"), "https://api.mapbox.com/styles/v1/user/style/draft?access_token=key"); - EXPECT_EQ(mbgl::util::mapbox::normalizeStyleURL("http://path", "key"), "http://path"); + EXPECT_EQ( + "mapbox://foo", + mbgl::util::mapbox::normalizeStyleURL("mapbox://foo", "key")); + EXPECT_EQ( + "https://api.mapbox.com/styles/v1/user/style?access_token=key", + mbgl::util::mapbox::normalizeStyleURL("mapbox://styles/user/style", "key")); + EXPECT_EQ( + "https://api.mapbox.com/styles/v1/user/style/draft?access_token=key", + mbgl::util::mapbox::normalizeStyleURL("mapbox://styles/user/style/draft", "key")); + EXPECT_EQ( + "http://path", + mbgl::util::mapbox::normalizeStyleURL("http://path", "key")); } TEST(Mapbox, SpriteURL) { - EXPECT_EQ(mbgl::util::mapbox::normalizeSpriteURL("map/box/sprites@2x.json", "key"), "map/box/sprites@2x.json"); - EXPECT_EQ(mbgl::util::mapbox::normalizeSpriteURL("mapbox://foo", "key"), "mapbox://foo"); - EXPECT_EQ(mbgl::util::mapbox::normalizeSpriteURL("mapbox://sprites/mapbox/streets-v8.json", "key"), "https://api.mapbox.com/styles/v1/mapbox/streets-v8/sprite.json?access_token=key"); - EXPECT_EQ(mbgl::util::mapbox::normalizeSpriteURL("mapbox://sprites/mapbox/streets-v8@2x.png", "key"), "https://api.mapbox.com/styles/v1/mapbox/streets-v8/sprite@2x.png?access_token=key"); - EXPECT_EQ(mbgl::util::mapbox::normalizeSpriteURL("mapbox://sprites/mapbox/streets-v8/draft@2x.png", "key"), "https://api.mapbox.com/styles/v1/mapbox/streets-v8/draft/sprite@2x.png?access_token=key"); + EXPECT_EQ( + "map/box/sprites@2x.json", + mbgl::util::mapbox::normalizeSpriteURL("map/box/sprites@2x.json", "key")); + EXPECT_EQ( + "mapbox://foo", + mbgl::util::mapbox::normalizeSpriteURL("mapbox://foo", "key")); + EXPECT_EQ( + "https://api.mapbox.com/styles/v1/mapbox/streets-v8/sprite.json?access_token=key", + mbgl::util::mapbox::normalizeSpriteURL("mapbox://sprites/mapbox/streets-v8.json", "key")); + EXPECT_EQ( + "https://api.mapbox.com/styles/v1/mapbox/streets-v8/sprite@2x.png?access_token=key", + mbgl::util::mapbox::normalizeSpriteURL("mapbox://sprites/mapbox/streets-v8@2x.png", "key")); + EXPECT_EQ( + "https://api.mapbox.com/styles/v1/mapbox/streets-v8/draft/sprite@2x.png?access_token=key", + mbgl::util::mapbox::normalizeSpriteURL("mapbox://sprites/mapbox/streets-v8/draft@2x.png", "key")); + EXPECT_EQ( + "mapbox://sprites/mapbox/streets-v9?fresh=true.png", + mbgl::util::mapbox::normalizeSpriteURL( + "mapbox://sprites/mapbox/streets-v9?fresh=true.png", + "key")); + EXPECT_EQ("mapbox://////", mbgl::util::mapbox::normalizeSpriteURL("mapbox://////", "key")); } TEST(Mapbox, TileURL) { -- cgit v1.2.1 From 142e2b08174c3f5d1581da0e1cb700589500a8f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Tue, 19 Jul 2016 16:03:28 +0200 Subject: [android] #5725 - Cherry picking 40ea4247d81eccc1d48af56fe1da95438bbdefcc --- src/mbgl/util/mapbox.cpp | 78 +++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 41 deletions(-) diff --git a/src/mbgl/util/mapbox.cpp b/src/mbgl/util/mapbox.cpp index 15c369a995..b60c04a3ed 100644 --- a/src/mbgl/util/mapbox.cpp +++ b/src/mbgl/util/mapbox.cpp @@ -19,14 +19,15 @@ bool isMapboxURL(const std::string& url) { std::vector getMapboxURLPathname(const std::string& url) { std::vector pathname; - std::size_t startIndex = protocol.length(); - while (startIndex < url.length()) { - std::size_t endIndex = url.find("/", startIndex); - if (endIndex == std::string::npos) { - endIndex = url.find_first_of("?#"); - } + auto startIndex = protocol.length(); + auto end = url.find_first_of("?#"); + if (end == std::string::npos) { + end = url.length(); + } + while (startIndex < end) { + auto endIndex = url.find("/", startIndex); if (endIndex == std::string::npos) { - endIndex = url.length(); + endIndex = end; } pathname.push_back(url.substr(startIndex, endIndex - startIndex)); startIndex = endIndex + 1; @@ -51,16 +52,15 @@ std::string normalizeStyleURL(const std::string& url, const std::string& accessT return url; } - std::vector pathname = getMapboxURLPathname(url); - + const auto pathname = getMapboxURLPathname(url); if (pathname.size() < 3) { Log::Error(Event::ParseStyle, "Invalid style URL"); return url; } - std::string user = pathname[1]; - std::string id = pathname[2]; - bool isDraft = pathname.size() > 3; + const auto& user = pathname[1]; + const auto& id = pathname[2]; + const bool isDraft = pathname.size() > 3; return baseURL + "styles/v1/" + user + "/" + id + (isDraft ? "/draft" : "") + "?access_token=" + accessToken; } @@ -69,36 +69,33 @@ std::string normalizeSpriteURL(const std::string& url, const std::string& access return url; } - std::vector pathname = getMapboxURLPathname(url); - + const auto pathname = getMapboxURLPathname(url); if (pathname.size() < 3) { Log::Error(Event::ParseStyle, "Invalid sprite URL"); return url; } - std::string user = pathname[1]; - bool isDraft = pathname.size() > 3; + const auto& user = pathname[1]; + const bool isDraft = pathname.size() > 3; + + const auto& name = isDraft ? pathname[3] : pathname[2]; + const size_t index = name.find_first_of("@."); + if (index == std::string::npos) { + Log::Error(Event::ParseStyle, "Invalid sprite URL"); + return url; + } + const auto& extension = name.substr(index); - std::string id, extension; if (isDraft) { - size_t index = pathname[3].find_first_of("@."); - if (index == std::string::npos) { - Log::Error(Event::ParseStyle, "Invalid sprite URL"); - return url; - } - id = pathname[2]; - extension = pathname[3].substr(index); + const auto& id = pathname[2]; + return baseURL + "styles/v1/" + user + "/" + id + "/draft/sprite" + extension + + "?access_token=" + accessToken; + } else { - size_t index = pathname[2].find_first_of("@."); - if (index == std::string::npos) { - Log::Error(Event::ParseStyle, "Invalid sprite URL"); - return url; - } - id = pathname[2].substr(0, index); - extension = pathname[2].substr(index); + const auto& id = pathname[2].substr(0, index); + return baseURL + "styles/v1/" + user + "/" + id + "/sprite" + extension + "?access_token=" + + accessToken; } - - return baseURL + "styles/v1/" + user + "/" + id + "/" + (isDraft ? "draft/" : "") + "sprite" + extension + "?access_token=" + accessToken; } std::string normalizeGlyphsURL(const std::string& url, const std::string& accessToken) { @@ -106,16 +103,15 @@ std::string normalizeGlyphsURL(const std::string& url, const std::string& access return url; } - std::vector pathname = getMapboxURLPathname(url); - + const auto pathname = getMapboxURLPathname(url); if (pathname.size() < 4) { Log::Error(Event::ParseStyle, "Invalid glyph URL"); return url; } - std::string user = pathname[1]; - std::string fontstack = pathname[2]; - std::string range = pathname[3]; + const auto& user = pathname[1]; + const auto& fontstack = pathname[2]; + const auto& range = pathname[3]; return baseURL + "fonts/v1/" + user + "/" + fontstack + "/" + range + "?access_token=" + accessToken; } @@ -136,7 +132,7 @@ std::string canonicalizeTileURL(const std::string& url, SourceType type, uint16_ tilesetStartIdx += sizeof("/v4/") - 1; - auto tilesetEndIdx = url.find("/", tilesetStartIdx); + const auto tilesetEndIdx = url.find("/", tilesetStartIdx); if (tilesetEndIdx == std::string::npos) { return url; } @@ -153,12 +149,12 @@ std::string canonicalizeTileURL(const std::string& url, SourceType type, uint16_ basenameIdx += 1; } - auto extensionIdx = url.find(".", basenameIdx); + const auto extensionIdx = url.find(".", basenameIdx); if (extensionIdx == std::string::npos || extensionIdx == queryIdx - 1) { return url; } - auto tileset = url.substr(tilesetStartIdx, tilesetEndIdx - tilesetStartIdx); + const auto tileset = url.substr(tilesetStartIdx, tilesetEndIdx - tilesetStartIdx); auto extension = url.substr(extensionIdx + 1, queryIdx - extensionIdx - 1); #if !defined(__ANDROID__) && !defined(__APPLE__) && !defined(QT_IMAGE_DECODERS) -- cgit v1.2.1 From 97f5bb0ff7c31a4961987aa4c802757938bbb6de Mon Sep 17 00:00:00 2001 From: Brad Leege Date: Tue, 19 Jul 2016 13:49:20 -0500 Subject: [android] #5725 - Updating version to 4.1.1 --- platform/android/MapboxGLAndroidSDK/gradle.properties | 2 +- .../resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/gradle.properties b/platform/android/MapboxGLAndroidSDK/gradle.properties index c20b64522b..d28522f5d1 100644 --- a/platform/android/MapboxGLAndroidSDK/gradle.properties +++ b/platform/android/MapboxGLAndroidSDK/gradle.properties @@ -1,5 +1,5 @@ GROUP=com.mapbox.mapboxsdk -VERSION_NAME=4.1.0 +VERSION_NAME=4.1.1 POM_DESCRIPTION=Mapbox GL Android SDK POM_URL=https://github.com/mapbox/mapbox-gl-native diff --git a/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties b/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties index 73a37c7c6f..63cccc00ef 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties +++ b/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties @@ -1,3 +1,3 @@ fabric-identifier=com.mapbox.mapboxsdk.mapbox-android-sdk -fabric-version=4.1.0 +fabric-version=4.1.1 fabric-build-type=binary -- cgit v1.2.1 From 5ef2cbf9422feda02a79bdefea88fb13d7830f79 Mon Sep 17 00:00:00 2001 From: Brad Leege Date: Tue, 19 Jul 2016 16:15:27 -0500 Subject: [android] #5725 - Updating CHANGELOG --- platform/android/CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/platform/android/CHANGELOG.md b/platform/android/CHANGELOG.md index 39acfe1593..185956cb94 100644 --- a/platform/android/CHANGELOG.md +++ b/platform/android/CHANGELOG.md @@ -2,6 +2,12 @@ Mapbox welcomes participation and contributions from everyone. If you'd like to do so please see the [`Contributing Guide`](https://github.com/mapbox/mapbox-gl-native/blob/master/CONTRIBUTING.md) first to get started. +## 4.1.1 + +Mapbox Android 4.1.1 is a patch release and is recommended to upgrade to it as soon as possible. + +* Default Styles Caching Crash ([#5722](https://github.com/mapbox/mapbox-gl-native/issues/5722)) + ## 4.1.0 Mapbox Android 4.1.0 builds off our ambitious 4.0.0 version with 3 major new features being released. -- cgit v1.2.1