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

Commit

Permalink
[core] add check for missing sprite URL file extension
Browse files Browse the repository at this point in the history
Cherry-picked from 559f3a6.
  • Loading branch information
kkaefer authored and 1ec5 committed Jul 19, 2016
1 parent 12b431e commit d640c22
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/mbgl/util/mapbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,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);
}
Expand Down
6 changes: 6 additions & 0 deletions test/util/mapbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ TEST(Mapbox, SpriteURL) {
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) {
Expand Down

0 comments on commit d640c22

Please sign in to comment.