[core] include leading slash in URL.path

This commit is contained in:
Konstantin Käfer
2017-01-17 15:17:33 +01:00
parent 7983e3a67c
commit 4b0cb858ba
3 changed files with 30 additions and 35 deletions

View File

@@ -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);

View File

@@ -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 };
}()) {

View File

@@ -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);
}