]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
urlapi: drop base fragment on empty redirect
authortiymat <138939221+tiymat@users.noreply.github.com>
Wed, 27 May 2026 02:02:32 +0000 (23:32 -0230)
committerDaniel Stenberg <daniel@haxx.se>
Sun, 31 May 2026 21:36:16 +0000 (23:36 +0200)
Extended test 1560 to verify

Fixes #21745
Closes #21763

lib/urlapi.c
tests/data/test1560
tests/libtest/lib1560.c

index a5ec95032b4623aa1fc623885dcc35d490ed794e..d92887bf885763a608fdfdcfd8a56a32870c9054 100644 (file)
@@ -1721,8 +1721,11 @@ static CURLUcode set_url(CURLU *u, const char *url, size_t part_size,
        and this is a redirect */
     uc = curl_url_get(u, CURLUPART_URL, &oldurl, flags);
     if(!uc) {
-      /* success, meaning the "" is a fine relative URL, but nothing
-         changes */
+      /* success, meaning the "" is a fine relative URL, and the new URL
+         inherits scheme/authority/path/query, but not fragment, from the
+         existing URL (RFC 3986 section 5.2.2) */
+      curlx_safefree(u->fragment);
+      u->fragment_present = FALSE;
       curlx_free(oldurl);
       return CURLUE_OK;
     }
index e27229739f8e56636d281eeb19d54a35155171a8..7f78aece2f13edd0722ff43c7d1292caaa949fa3 100644 (file)
@@ -37,7 +37,7 @@ lib%TESTNUMBER
 success
 </stdout>
 <limits>
-Allocations: 3200
+Allocations: 3250
 </limits>
 </verify>
 </testcase>
index bdf8b56cad5b9370c40a6233524ca2c18e14faf2..a62d9334b223c76d719156f7b170454118865dee 100644 (file)
@@ -1356,6 +1356,33 @@ static const struct redircase set_url_list[] = {
    "", /* blank redirect */
    "https://example.com/",
    0, 0, CURLUE_OK },
+  {"file:///test?test#test",
+   "", "file:///test?test",
+   0, 0, CURLUE_OK},
+  {"https://example.com/path?query#frag",
+   "", "https://example.com/path?query",
+   0, 0, CURLUE_OK},
+  {"ftp://example.com/dir/file#anchor",
+   "", "ftp://example.com/dir/file",
+   0, 0, CURLUE_OK},
+  {"http://example.com/path#frag",
+   "", "http://example.com/path",
+   0, 0, CURLUE_OK},
+  {"http://example.com/#frag",
+   "", "http://example.com/",
+   0, 0, CURLUE_OK},
+  {"http://user:pass@example.com/path?query#frag",
+   "", "http://user:pass@example.com/path?query",
+   0, 0, CURLUE_OK},
+  {"http://example.com:8080/path?query#frag",
+   "", "http://example.com:8080/path?query",
+   0, 0, CURLUE_OK},
+  {"https://user:pass@example.com:8443/path?query#frag",
+   "", "https://user:pass@example.com:8443/path?query",
+   0, 0, CURLUE_OK},
+  {"http://[::1]/path#frag",
+   "", "http://[::1]/path",
+   0, 0, CURLUE_OK},
   {"http://firstplace.example.com/want/1314",
    "//somewhere.example.com/reply/1314",
    "http://somewhere.example.com/reply/1314",