[core] add check for missing sprite URL file extension
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user