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-17 17:31:59 -0700
commit9c12a311f2ba2b26a44a6e13edd38bf8050e5d16 (patch)
tree688a1c9b77d5548be20bab85d97b0216b5cfb4e3
parent0cd646180e787a59e600cb184b189a801e261c5c (diff)
downloadqtlocation-mapboxgl-9c12a311f2ba2b26a44a6e13edd38bf8050e5d16.tar.gz
[core] correctly alter sprite URLs when attaching sprite.png/sprite.json filenames
-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 e75302b986..207dd2ee69 100644
--- a/src/mbgl/storage/resource.cpp
+++ b/src/mbgl/storage/resource.cpp
@@ -61,17 +61,19 @@ Resource Resource::image(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 5a27aa98a5..083134c4d0 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, Image) {
@@ -129,4 +133,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);
}