Fix #1626 - ignore @ in query string

This commit is contained in:
Sergey Lyubka 2022-07-10 15:41:11 +01:00
parent 9876e3afd7
commit f40b272eeb
3 changed files with 9 additions and 6 deletions

View File

@ -5307,19 +5307,19 @@ static struct url urlparse(const char *url) {
struct url u;
memset(&u, 0, sizeof(u));
for (i = 0; url[i] != '\0'; i++) {
if (i > 0 && u.host == 0 && url[i - 1] == '/' && url[i] == '/') {
if (url[i] == '/' && i > 0 && u.host == 0 && url[i - 1] == '/') {
u.host = i + 1;
u.port = 0;
} else if (url[i] == ']') {
u.port = 0; // IPv6 URLs, like http://[::1]/bar
} else if (url[i] == ':' && u.port == 0 && u.uri == 0) {
u.port = i + 1;
} else if (url[i] == '@' && u.user == 0 && u.pass == 0) {
} else if (url[i] == '@' && u.user == 0 && u.pass == 0 && u.uri == 0) {
u.user = u.host;
u.pass = u.port;
u.host = i + 1;
u.port = 0;
} else if (u.host && u.uri == 0 && url[i] == '/') {
} else if (url[i] == '/' && u.host && u.uri == 0) {
u.uri = i;
}
}

View File

@ -15,19 +15,19 @@ static struct url urlparse(const char *url) {
struct url u;
memset(&u, 0, sizeof(u));
for (i = 0; url[i] != '\0'; i++) {
if (i > 0 && u.host == 0 && url[i - 1] == '/' && url[i] == '/') {
if (url[i] == '/' && i > 0 && u.host == 0 && url[i - 1] == '/') {
u.host = i + 1;
u.port = 0;
} else if (url[i] == ']') {
u.port = 0; // IPv6 URLs, like http://[::1]/bar
} else if (url[i] == ':' && u.port == 0 && u.uri == 0) {
u.port = i + 1;
} else if (url[i] == '@' && u.user == 0 && u.pass == 0) {
} else if (url[i] == '@' && u.user == 0 && u.pass == 0 && u.uri == 0) {
u.user = u.host;
u.pass = u.port;
u.host = i + 1;
u.port = 0;
} else if (u.host && u.uri == 0 && url[i] == '/') {
} else if (url[i] == '/' && u.host && u.uri == 0) {
u.uri = i;
}
}

View File

@ -219,6 +219,8 @@ static void test_url(void) {
ASSERT(vcmp(mg_url_user("p://u:p@foo"), "u"));
ASSERT(vcmp(mg_url_pass("p://u:p@foo"), "p"));
ASSERT(vcmp(mg_url_pass("p://u:p@foo//a@b"), "p"));
ASSERT(vcmp(mg_url_user("p://foo/q?mail=a@b.c"), ""));
ASSERT(vcmp(mg_url_pass("p://foo/q?mail=a@b.c"), ""));
// URI
ASSERT(strcmp(mg_url_uri("p://foo"), "/") == 0);
@ -228,6 +230,7 @@ static void test_url(void) {
ASSERT(strcmp(mg_url_uri("p://foo:12/a/b/c"), "/a/b/c") == 0);
ASSERT(strcmp(mg_url_uri("p://[::1]:12/a/b/c"), "/a/b/c") == 0);
ASSERT(strcmp(mg_url_uri("p://[ab::1]:12/a/b/c"), "/a/b/c") == 0);
ASSERT(strcmp(mg_url_uri("p://foo/q?mail=a@b.c"), "/q?mail=a@b.c") == 0);
}
static void test_base64(void) {