summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2017-10-17 14:00:52 -0700
committerKonstantin Käfer <mail@kkaefer.com>2017-10-18 09:12:15 -0700
commit17f303e1040a5a0453632d36ab1ac017dfb49dc8 (patch)
treeeb3fc3c29dde85205b0a3e0c7aea62473f9e7ad9
parent9c22a0c83534adb6c110170404fb8743e475f275 (diff)
downloadqtlocation-mapboxgl-upstream/release-ios-v3.6.0-android-v5.1.0__sprite-query-parameters.tar.gz
[core] correctly alter sprite URLs when attaching sprite.png/sprite.json filenamesupstream/release-ios-v3.6.0-android-v5.1.0__sprite-query-parameters
-rw-r--r--src/mbgl/storage/resource.cpp18
-rw-r--r--test/storage/resource.test.cpp8
2 files changed, 18 insertions, 8 deletions
diff --git a/src/mbgl/storage/resource.cpp b/src/mbgl/storage/resource.cpp
index 20dde1db56..977c98dc1c 100644
--- a/src/mbgl/storage/resource.cpp
+++ b/src/mbgl/storage/resource.cpp
@@ -54,17 +54,19 @@ Resource Resource::source(const std::string& url) {
}
Resource Resource::spriteImage(const std::string& base, float pixelRatio) {
- return Resource {
- Resource::Kind::SpriteImage,
- base + (pixelRatio > 1 ? "@2x" : "") + ".png"
- };
+ util::URL url(base);
+ return Resource{ Resource::Kind::SpriteImage,
+ base.substr(0, url.path.first + url.path.second) +
+ (pixelRatio > 1 ? "@2x" : "") + ".png" +
+ base.substr(url.query.first, url.query.second) };
}
Resource Resource::spriteJSON(const std::string& base, float pixelRatio) {
- return Resource {
- Resource::Kind::SpriteJSON,
- base + (pixelRatio > 1 ? "@2x" : "") + ".json"
- };
+ util::URL url(base);
+ return Resource{ Resource::Kind::SpriteJSON,
+ base.substr(0, url.path.first + url.path.second) +
+ (pixelRatio > 1 ? "@2x" : "") + ".json" +
+ base.substr(url.query.first, url.query.second) };
}
Resource Resource::glyphs(const std::string& urlTemplate, const FontStack& fontStack, const std::pair<uint16_t, uint16_t>& glyphRange) {
diff --git a/test/storage/resource.test.cpp b/test/storage/resource.test.cpp
index 1c15fe6503..7c4b69160e 100644
--- a/test/storage/resource.test.cpp
+++ b/test/storage/resource.test.cpp
@@ -115,6 +115,10 @@ TEST(Resource, SpriteImage) {
Resource resource = Resource::spriteImage("http://example.com/sprite", 2.0);
EXPECT_EQ(Resource::Kind::SpriteImage, resource.kind);
EXPECT_EQ("http://example.com/sprite@2x.png", resource.url);
+
+ Resource paramResource = Resource::spriteImage("http://example.com/sprite?query=true", 2.0);
+ EXPECT_EQ(Resource::Kind::SpriteImage, paramResource.kind);
+ EXPECT_EQ("http://example.com/sprite@2x.png?query=true", paramResource.url);
}
TEST(Resource, SpriteJSON) {
@@ -122,4 +126,8 @@ TEST(Resource, SpriteJSON) {
Resource resource = Resource::spriteJSON("http://example.com/sprite", 2.0);
EXPECT_EQ(Resource::Kind::SpriteJSON, resource.kind);
EXPECT_EQ("http://example.com/sprite@2x.json", resource.url);
+
+ Resource paramResource = Resource::spriteJSON("http://example.com/sprite?query=true", 2.0);
+ EXPECT_EQ(Resource::Kind::SpriteJSON, paramResource.kind);
+ EXPECT_EQ("http://example.com/sprite@2x.json?query=true", paramResource.url);
}