urlapi: fix redirect to a new fragment or query (only)

The redirect logic was broken when the redirect-to URL was a relative
URL only as a fragment or query (starting with '#' or '?').

Extended test 1560 to reproduce, then verify.

Reported-by: Jeroen Ooms
Fixes #15836
Closes #15848
This commit is contained in:
Daniel Stenberg 2024-12-28 14:47:01 +01:00
parent 687a62f100
commit 66e5351e0a
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
4 changed files with 66 additions and 86 deletions

View file

@ -1143,6 +1143,38 @@ static CURLUcode updateurl(CURLU *u, const char *cmd, unsigned int setflags)
}
static const struct redircase set_url_list[] = {
{"http://example.org#withs/ash", "/moo#frag",
"http://example.org/moo#frag",
0, 0, CURLUE_OK},
{"http://example.org/", "../path/././../././../moo",
"http://example.org/moo",
0, 0, CURLUE_OK},
{"http://example.org?bar/moo", "?weird",
"http://example.org/?weird", 0, 0, CURLUE_OK},
{"http://example.org/foo?bar", "?weird",
"http://example.org/foo?weird", 0, 0, CURLUE_OK},
{"http://example.org/foo", "?weird",
"http://example.org/foo?weird", 0, 0, CURLUE_OK},
{"http://example.org", "?weird",
"http://example.org/?weird", 0, 0, CURLUE_OK},
{"http://example.org/#original", "?weird#moo",
"http://example.org/?weird#moo", 0, 0, CURLUE_OK},
{"http://example.org?bar/moo#yes/path", "#new/slash",
"http://example.org/?bar/moo#new/slash", 0, 0, CURLUE_OK},
{"http://example.org/foo?bar", "#weird",
"http://example.org/foo?bar#weird", 0, 0, CURLUE_OK},
{"http://example.org/foo?bar#original", "#weird",
"http://example.org/foo?bar#weird", 0, 0, CURLUE_OK},
{"http://example.org/foo#original", "#weird",
"http://example.org/foo#weird", 0, 0, CURLUE_OK},
{"http://example.org/#original", "#weird",
"http://example.org/#weird", 0, 0, CURLUE_OK},
{"http://example.org#original", "#weird",
"http://example.org/#weird", 0, 0, CURLUE_OK},
{"http://example.org/foo?bar", "moo?hey#weird",
"http://example.org/moo?hey#weird", 0, 0, CURLUE_OK},
{"http://example.org/",
"../path/././../../moo",
"http://example.org/moo",