]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
curl: do NOT append file name to path for upload when there's a query
authorDaniel Stenberg <daniel@haxx.se>
Fri, 14 Apr 2023 21:46:51 +0000 (23:46 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Sat, 15 Apr 2023 08:52:33 +0000 (10:52 +0200)
Added test 425 to verify.

Reported-by: Dirk Rosenkranz
Bug: https://curl.se/mail/archive-2023-04/0008.html
Closes #10969

src/tool_operhlp.c
tests/data/Makefile.inc
tests/data/test425 [new file with mode: 0644]

index f11d65a94adb811dad3db26b75d3e6c8ff295adb..9b70edd23cb4db8fbf6ba64619f68bb0899ca1dd 100644 (file)
@@ -95,6 +95,7 @@ CURLcode add_file_name_to_url(CURL *curl, char **inurlp, const char *filename)
   CURLUcode uerr;
   CURLU *uh = curl_url();
   char *path = NULL;
+  char *query = NULL;
   if(uh) {
     char *ptr;
     uerr = curl_url_set(uh, CURLUPART_URL, *inurlp,
@@ -108,7 +109,13 @@ CURLcode add_file_name_to_url(CURL *curl, char **inurlp, const char *filename)
       result = urlerr_cvt(uerr);
       goto fail;
     }
-
+    uerr = curl_url_get(uh, CURLUPART_QUERY, &query, 0);
+    if(query) {
+      curl_free(query);
+      curl_free(path);
+      curl_url_cleanup(uh);
+      return CURLE_OK;
+    }
     ptr = strrchr(path, '/');
     if(!ptr || !*++ptr) {
       /* The URL path has no file name part, add the local file name. In order
index ca5903fe7d73f6f6566d4dcdffcca05c4d1c1512..ffd33f656eb9fdf5295af1625592cbdde83cc6a7 100644 (file)
@@ -68,7 +68,7 @@ test380 test381 test383 test384 test385 test386 test387 test388 test389 \
 test390 test391 test392 test393 test394 test395 test396 test397 test398 \
 test399 test400 test401 test402 test403 test404 test405 test406 test407 \
 test408 test409 test410 test411 test412 test413 test414 test415 test416 \
-test417 test418 test419 test420 test421 test422 test423 test424 \
+test417 test418 test419 test420 test421 test422 test423 test424 test425 \
 \
 test430 test431 test432 test433 test434 test435 test436 \
 \
diff --git a/tests/data/test425 b/tests/data/test425
new file mode 100644 (file)
index 0000000..1ce92af
--- /dev/null
@@ -0,0 +1,53 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP PUT
+</keywords>
+</info>
+
+#
+# Server-side
+<reply>
+<data crlf="yes">
+HTTP/1.1 200 OK
+Date: Tue, 09 Nov 2010 14:49:00 GMT
+Content-Length: 6
+Connection: close
+Content-Type: text/html
+
+-foo-
+</data>
+</reply>
+
+#
+# Client-side
+<client>
+<server>
+http
+</server>
+ <name>
+HTTP PUT with path ending with slash + query
+ </name>
+ <command>
+-T log/up%TESTNUMBER http://%HOSTIP:%HTTPPORT/%TESTNUMBER/?fullpath
+</command>
+<file name="log/up%TESTNUMBER">
+content
+</file>
+</client>
+
+#
+# Verify data after the test has been "shot"
+<verify>
+<protocol>
+PUT /%TESTNUMBER/?fullpath HTTP/1.1\r
+Host: %HOSTIP:%HTTPPORT\r
+User-Agent: curl/%VERSION\r
+Accept: */*\r
+Content-Length: 8\r
+\r
+content
+</protocol>
+</verify>
+</testcase>