summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2017-01-17 15:17:33 +0100
committerKonstantin Käfer <mail@kkaefer.com>2017-01-17 17:38:57 +0100
commit4b0cb858baa7edd9510ec08ef22e53df25fb3bc2 (patch)
treeea064acfd67a28a7c4e4f1c90cd98a320abcaeca
parent7983e3a67c557a0fcf118984404ea1756416b521 (diff)
downloadqtlocation-mapboxgl-4b0cb858baa7edd9510ec08ef22e53df25fb3bc2.tar.gz
[core] include leading slash in URL.path
-rw-r--r--src/mbgl/util/mapbox.cpp10
-rw-r--r--src/mbgl/util/url.cpp5
-rw-r--r--test/util/url.test.cpp50
3 files changed, 30 insertions, 35 deletions
diff --git a/src/mbgl/util/mapbox.cpp b/src/mbgl/util/mapbox.cpp
index 642945ba07..c03cc2a8e7 100644
--- a/src/mbgl/util/mapbox.cpp
+++ b/src/mbgl/util/mapbox.cpp
@@ -56,7 +56,7 @@ std::string normalizeStyleURL(const std::string& baseURL,
return str;
}
- const auto tpl = baseURL + "/styles/v1/{path}?access_token=" + accessToken;
+ const auto tpl = baseURL + "/styles/v1{path}?access_token=" + accessToken;
return transformURL(tpl, str, url);
}
@@ -74,7 +74,7 @@ std::string normalizeSpriteURL(const std::string& baseURL,
}
const auto tpl =
- baseURL + "/styles/v1/{directory}{filename}/sprite{extension}?access_token=" + accessToken;
+ baseURL + "/styles/v1{directory}{filename}/sprite{extension}?access_token=" + accessToken;
return transformURL(tpl, str, url);
}
@@ -91,7 +91,7 @@ std::string normalizeGlyphsURL(const std::string& baseURL,
return str;
}
- const auto tpl = baseURL + "/fonts/v1/{path}?access_token=" + accessToken;
+ const auto tpl = baseURL + "/fonts/v1{path}?access_token=" + accessToken;
return transformURL(tpl, str, url);
}
@@ -108,13 +108,13 @@ std::string normalizeTileURL(const std::string& baseURL,
return str;
}
- const auto tpl = baseURL + "/v4/{path}?access_token=" + accessToken;
+ const auto tpl = baseURL + "/v4{path}?access_token=" + accessToken;
return transformURL(tpl, str, url);
}
std::string
canonicalizeTileURL(const std::string& str, const SourceType type, const uint16_t tileSize) {
- const char* version = "v4/";
+ const char* version = "/v4/";
const size_t versionLen = strlen(version);
const URL url(str);
diff --git a/src/mbgl/util/url.cpp b/src/mbgl/util/url.cpp
index f070135213..0a7d096ec0 100644
--- a/src/mbgl/util/url.cpp
+++ b/src/mbgl/util/url.cpp
@@ -107,11 +107,6 @@ URL::URL(const std::string& str)
if (isData) {
// Skip comma
pathPos++;
- } else {
- // Skip optional leading slash
- while (pathPos < query.first && (str[pathPos] == '/')) {
- ++pathPos;
- }
}
return { pathPos, query.first - pathPos };
}()) {
diff --git a/test/util/url.test.cpp b/test/util/url.test.cpp
index 00b761ce2e..242943f75a 100644
--- a/test/util/url.test.cpp
+++ b/test/util/url.test.cpp
@@ -76,15 +76,15 @@ TEST(URL, Domain) {
}
TEST(URL, Path) {
- EXPECT_EQ(URL::Segment({ 19, 4 }), URL("http://example.com/test?query=foo").path);
- EXPECT_EQ(URL::Segment({ 19, 4 }), URL("http://example.com/test?query=foo#bar").path);
- EXPECT_EQ(URL::Segment({ 19, 4 }), URL("http://example.com/test#bar").path);
+ EXPECT_EQ(URL::Segment({ 18, 5 }), URL("http://example.com/test?query=foo").path);
+ EXPECT_EQ(URL::Segment({ 18, 5 }), URL("http://example.com/test?query=foo#bar").path);
+ EXPECT_EQ(URL::Segment({ 18, 5 }), URL("http://example.com/test#bar").path);
EXPECT_EQ(URL::Segment({ 18, 0 }), URL("http://example.com?query=foo").path);
EXPECT_EQ(URL::Segment({ 18, 0 }), URL("http://example.com#?query=foo").path);
- EXPECT_EQ(URL::Segment({ 19, 0 }), URL("http://example.com/?query=foo").path);
+ EXPECT_EQ(URL::Segment({ 18, 1 }), URL("http://example.com/?query=foo").path);
EXPECT_EQ(URL::Segment({ 3, 0 }), URL(":::").path);
EXPECT_EQ(URL::Segment({ 13, 0 }), URL("http://domain").path);
- EXPECT_EQ(URL::Segment({ 7, 3 }), URL("domain/foo?bar").path);
+ EXPECT_EQ(URL::Segment({ 6, 4 }), URL("domain/foo?bar").path);
EXPECT_EQ(URL::Segment({ 6, 17 }), URL("data:,Hello%2C%20World!").path);
EXPECT_EQ(URL::Segment({ 23, 24 }), URL("data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D").path);
}
@@ -105,26 +105,26 @@ TEST(Path, Directory) {
}
TEST(Path, URLDirectory) {
- EXPECT_EQ(Path::Segment({ 19, 8 }), URLPath("http://example.com/foo/bar/baz.ext").directory);
- EXPECT_EQ(Path::Segment({ 19, 8 }), URLPath("http://example.com/foo/bar/baz.ext?query=foo.bar").directory);
- EXPECT_EQ(Path::Segment({ 19, 8 }), URLPath("http://example.com/foo.bar/baz.ext").directory);
- EXPECT_EQ(Path::Segment({ 19, 8 }), URLPath("http://example.com/foo.bar/baz.ext?query=foo.bar").directory);
- EXPECT_EQ(Path::Segment({ 19, 8 }), URLPath("http://example.com/foo.bar/baz").directory);
- EXPECT_EQ(Path::Segment({ 19, 8 }), URLPath("http://example.com/foo.bar/baz?query=foo.bar").directory);
- EXPECT_EQ(Path::Segment({ 19, 8 }), URLPath("http://example.com/foo/bar/.ext").directory);
- EXPECT_EQ(Path::Segment({ 19, 8 }), URLPath("http://example.com/foo/bar/.ext?query=foo.bar").directory);
- EXPECT_EQ(Path::Segment({ 19, 4 }), URLPath("http://example.com/foo/bar@2x.png").directory);
- EXPECT_EQ(Path::Segment({ 19, 4 }), URLPath("http://example.com/foo/bar@2x.png?query=foo.bar").directory);
- EXPECT_EQ(Path::Segment({ 19, 4 }), URLPath("http://example.com/foo/b").directory);
- EXPECT_EQ(Path::Segment({ 19, 4 }), URLPath("http://example.com/foo/b?query=foo.bar").directory);
- EXPECT_EQ(Path::Segment({ 19, 4 }), URLPath("http://example.com/foo/").directory);
- EXPECT_EQ(Path::Segment({ 19, 4 }), URLPath("http://example.com/foo/?query=foo.bar").directory);
- EXPECT_EQ(Path::Segment({ 19, 0 }), URLPath("http://example.com/foo").directory);
- EXPECT_EQ(Path::Segment({ 19, 0 }), URLPath("http://example.com/foo?query=foo.bar").directory);
- EXPECT_EQ(Path::Segment({ 19, 0 }), URLPath("http://example.com/foo.png").directory);
- EXPECT_EQ(Path::Segment({ 19, 0 }), URLPath("http://example.com/foo.png?query=foo.bar").directory);
- EXPECT_EQ(Path::Segment({ 19, 0 }), URLPath("http://example.com/").directory);
- EXPECT_EQ(Path::Segment({ 19, 0 }), URLPath("http://example.com/?query=foo.bar").directory);
+ EXPECT_EQ(Path::Segment({ 18, 9 }), URLPath("http://example.com/foo/bar/baz.ext").directory);
+ EXPECT_EQ(Path::Segment({ 18, 9 }), URLPath("http://example.com/foo/bar/baz.ext?query=foo.bar").directory);
+ EXPECT_EQ(Path::Segment({ 18, 9 }), URLPath("http://example.com/foo.bar/baz.ext").directory);
+ EXPECT_EQ(Path::Segment({ 18, 9 }), URLPath("http://example.com/foo.bar/baz.ext?query=foo.bar").directory);
+ EXPECT_EQ(Path::Segment({ 18, 9 }), URLPath("http://example.com/foo.bar/baz").directory);
+ EXPECT_EQ(Path::Segment({ 18, 9 }), URLPath("http://example.com/foo.bar/baz?query=foo.bar").directory);
+ EXPECT_EQ(Path::Segment({ 18, 9 }), URLPath("http://example.com/foo/bar/.ext").directory);
+ EXPECT_EQ(Path::Segment({ 18, 9 }), URLPath("http://example.com/foo/bar/.ext?query=foo.bar").directory);
+ EXPECT_EQ(Path::Segment({ 18, 5 }), URLPath("http://example.com/foo/bar@2x.png").directory);
+ EXPECT_EQ(Path::Segment({ 18, 5 }), URLPath("http://example.com/foo/bar@2x.png?query=foo.bar").directory);
+ EXPECT_EQ(Path::Segment({ 18, 5 }), URLPath("http://example.com/foo/b").directory);
+ EXPECT_EQ(Path::Segment({ 18, 5 }), URLPath("http://example.com/foo/b?query=foo.bar").directory);
+ EXPECT_EQ(Path::Segment({ 18, 5 }), URLPath("http://example.com/foo/").directory);
+ EXPECT_EQ(Path::Segment({ 18, 5 }), URLPath("http://example.com/foo/?query=foo.bar").directory);
+ EXPECT_EQ(Path::Segment({ 18, 1 }), URLPath("http://example.com/foo").directory);
+ EXPECT_EQ(Path::Segment({ 18, 1 }), URLPath("http://example.com/foo?query=foo.bar").directory);
+ EXPECT_EQ(Path::Segment({ 18, 1 }), URLPath("http://example.com/foo.png").directory);
+ EXPECT_EQ(Path::Segment({ 18, 1 }), URLPath("http://example.com/foo.png?query=foo.bar").directory);
+ EXPECT_EQ(Path::Segment({ 18, 1 }), URLPath("http://example.com/").directory);
+ EXPECT_EQ(Path::Segment({ 18, 1 }), URLPath("http://example.com/?query=foo.bar").directory);
EXPECT_EQ(Path::Segment({ 18, 0 }), URLPath("http://example.com").directory);
EXPECT_EQ(Path::Segment({ 18, 0 }), URLPath("http://example.com?query=foo.bar").directory);
}