Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Backport: Correctly alter sprite URLs #10217

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/mbgl/storage/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions test/storage/resource.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,19 @@ 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) {
using namespace mbgl;
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);
}