Better URL parsing
This commit is contained in:
parent
a515cf7c92
commit
a4adac8bf7
@ -61,9 +61,12 @@ namespace fr
|
|||||||
pos = url.find('/', parse_offset);
|
pos = url.find('/', parse_offset);
|
||||||
pos = (pos != std::string::npos) ? pos : url.find('?', parse_offset);
|
pos = (pos != std::string::npos) ? pos : url.find('?', parse_offset);
|
||||||
pos = (pos != std::string::npos) ? pos : url.find('#', parse_offset);
|
pos = (pos != std::string::npos) ? pos : url.find('#', parse_offset);
|
||||||
pos = (pos != std::string::npos) ? pos : url.size();
|
if(pos != std::string::npos || parse_offset != 0)
|
||||||
host = url.substr(parse_offset, pos - parse_offset);
|
{
|
||||||
parse_offset = pos + 1;
|
pos = (pos != std::string::npos) ? pos : url.size();
|
||||||
|
host = url.substr(parse_offset, pos - parse_offset);
|
||||||
|
parse_offset = pos + 1;
|
||||||
|
}
|
||||||
|
|
||||||
//Guess port based on scheme, if it's not explicitly provided.
|
//Guess port based on scheme, if it's not explicitly provided.
|
||||||
switch(scheme)
|
switch(scheme)
|
||||||
|
|||||||
@ -88,4 +88,28 @@ TEST(URLTest, test_modify_url)
|
|||||||
fr::URL url("https://example.com:2020");
|
fr::URL url("https://example.com:2020");
|
||||||
url.set_host("example.co.uk");
|
url.set_host("example.co.uk");
|
||||||
ASSERT_EQ(url.get_url(), "https://example.co.uk:2020");
|
ASSERT_EQ(url.get_url(), "https://example.co.uk:2020");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(URLTest, test_path_only_parse)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
fr::URL url("/bob");
|
||||||
|
ASSERT_TRUE(url.get_host().empty());
|
||||||
|
ASSERT_EQ(url.get_path(), "/bob");
|
||||||
|
}
|
||||||
|
{
|
||||||
|
fr::URL url("bob");
|
||||||
|
ASSERT_TRUE(url.get_host().empty());
|
||||||
|
ASSERT_EQ(url.get_path(), "/bob");
|
||||||
|
}
|
||||||
|
{
|
||||||
|
fr::URL url("http://bob");
|
||||||
|
ASSERT_EQ(url.get_host(), "bob");
|
||||||
|
ASSERT_TRUE(url.get_path().empty());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
fr::URL url("bob.com/trob");
|
||||||
|
ASSERT_EQ(url.get_host(), "bob.com");
|
||||||
|
ASSERT_EQ(url.get_path(), "/trob");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user