Recognise :PORT as a valid URL

This commit is contained in:
Sergey Lyubka 2021-11-29 13:57:33 +00:00
parent 81220fa590
commit 9731a51dae
3 changed files with 20 additions and 2 deletions

View File

@ -2398,6 +2398,13 @@ static bool mg_atonl(struct mg_str str, struct mg_addr *addr) {
return true;
}
static bool mg_atone(struct mg_str str, struct mg_addr *addr) {
if (str.len > 0) return false;
addr->ip = 0;
addr->is_ip6 = false;
return true;
}
static bool mg_aton4(struct mg_str str, struct mg_addr *addr) {
uint8_t data[4] = {0, 0, 0, 0};
size_t i, num_dots = 0;
@ -2474,7 +2481,8 @@ static bool mg_aton6(struct mg_str str, struct mg_addr *addr) {
bool mg_aton(struct mg_str str, struct mg_addr *addr) {
// LOG(LL_INFO, ("[%.*s]", (int) str.len, str.ptr));
return mg_atonl(str, addr) || mg_aton4(str, addr) || mg_aton6(str, addr);
return mg_atone(str, addr) || mg_atonl(str, addr) || mg_aton4(str, addr) ||
mg_aton6(str, addr);
}
void mg_mgr_free(struct mg_mgr *mgr) {

View File

@ -49,6 +49,13 @@ static bool mg_atonl(struct mg_str str, struct mg_addr *addr) {
return true;
}
static bool mg_atone(struct mg_str str, struct mg_addr *addr) {
if (str.len > 0) return false;
addr->ip = 0;
addr->is_ip6 = false;
return true;
}
static bool mg_aton4(struct mg_str str, struct mg_addr *addr) {
uint8_t data[4] = {0, 0, 0, 0};
size_t i, num_dots = 0;
@ -125,7 +132,8 @@ static bool mg_aton6(struct mg_str str, struct mg_addr *addr) {
bool mg_aton(struct mg_str str, struct mg_addr *addr) {
// LOG(LL_INFO, ("[%.*s]", (int) str.len, str.ptr));
return mg_atonl(str, addr) || mg_aton4(str, addr) || mg_aton6(str, addr);
return mg_atone(str, addr) || mg_atonl(str, addr) || mg_aton4(str, addr) ||
mg_aton6(str, addr);
}
void mg_mgr_free(struct mg_mgr *mgr) {

View File

@ -121,6 +121,7 @@ static void test_url(void) {
ASSERT(vcmp(mg_url_host("foo"), "foo"));
ASSERT(vcmp(mg_url_host("//foo"), "foo"));
ASSERT(vcmp(mg_url_host("foo:1234"), "foo"));
ASSERT(vcmp(mg_url_host(":1234"), ""));
ASSERT(vcmp(mg_url_host("//foo:1234"), "foo"));
ASSERT(vcmp(mg_url_host("p://foo"), "foo"));
ASSERT(vcmp(mg_url_host("p://foo/"), "foo"));
@ -141,6 +142,7 @@ static void test_url(void) {
// Port
ASSERT(mg_url_port("foo:1234") == 1234);
ASSERT(mg_url_port(":1234") == 1234);
ASSERT(mg_url_port("x://foo:1234") == 1234);
ASSERT(mg_url_port("x://foo:1234/") == 1234);
ASSERT(mg_url_port("x://foo:1234/xx") == 1234);