mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-11-28 21:08:28 +00:00
Only treat :// as a scheme separator before the path (#2701)
* Only treat :// as a scheme separator before the path parse_url looked for :// anywhere, so a redirect to a path whose query held a URL, such as /login?next=https://example.com/, was split at the query and rejected because the scheme was not letters only. * Check the path-with-query case in ParseUrlTest The redirect test resolves its relative case to the same input shape, and the case with a leading slash did not fit the test's name. --------- Co-authored-by: yhirose <yuji.hirose.bug@gmail.com>
This commit is contained in:
1 parent
ba9447efc4
commit
74180f0512
2 files changed
+11
-1
No files matched your search
@@ -925,7 +925,7 @@ inline bool parse_url(const std::string &url, UrlComponents &uc) {
|
|||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
|
|
||||||
auto sep = url.find("://");
|
auto sep = url.find("://");
|
||||||
if (sep != std::string::npos) {
|
if (sep < url.find_first_of("/?#")) {
|
||||||
// Schemes are case-insensitive (RFC 3986 3.1)
|
// Schemes are case-insensitive (RFC 3986 3.1)
|
||||||
uc.scheme = case_ignore::to_lower(url.substr(0, sep));
|
uc.scheme = case_ignore::to_lower(url.substr(0, sep));
|
||||||
|
|
||||||
|
|||||||
@@ -21681,6 +21681,8 @@ TEST(RedirectTest, RelativeLocationWithoutLeadingSlash) {
|
|||||||
const std::vector<std::pair<std::string, std::string>> cases = {
|
const std::vector<std::pair<std::string, std::string>> cases = {
|
||||||
{"next", "/dir/next"},
|
{"next", "/dir/next"},
|
||||||
{"./next?x=1", "/dir/next?x=1"},
|
{"./next?x=1", "/dir/next?x=1"},
|
||||||
|
{"next?source=https://example.com/catalog",
|
||||||
|
"/dir/next?source=https://example.com/catalog"},
|
||||||
{"../other", "/other"},
|
{"../other", "/other"},
|
||||||
};
|
};
|
||||||
for (const auto &c : cases) {
|
for (const auto &c : cases) {
|
||||||
@@ -22397,6 +22399,14 @@ TEST(ParseUrlTest, SchemeEdgeCases) {
|
|||||||
ASSERT_TRUE(detail::parse_url("httpS://example.com/path", uc));
|
ASSERT_TRUE(detail::parse_url("httpS://example.com/path", uc));
|
||||||
EXPECT_EQ("https", uc.scheme);
|
EXPECT_EQ("https", uc.scheme);
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
detail::UrlComponents uc;
|
||||||
|
ASSERT_TRUE(detail::parse_url("/path?next=https://example.com/", uc));
|
||||||
|
EXPECT_TRUE(uc.scheme.empty());
|
||||||
|
EXPECT_TRUE(uc.host.empty());
|
||||||
|
EXPECT_EQ("/path", uc.path);
|
||||||
|
EXPECT_EQ("?next=https://example.com/", uc.query);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ParseUrlTest, PortEdgeCases) {
|
TEST(ParseUrlTest, PortEdgeCases) {
|
||||||
|
|||||||
Reference in new issue
Block a user