tool_operhlp: iterate through all slashes to find name

If there is no trailing file name for -O or --remote-name-all, continue
searching until there is no more to search. A URL ending with multiple
slashes would previously make it do wrong.

Add test 1639 and 1644 to verify.

Follow-up to e26eefd9ce

Reported-by: James Fuller

Closes #21165
This commit is contained in:
Daniel Stenberg 2026-03-30 23:34:14 +02:00
parent bae6237c45
commit 8e89646a3d
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
4 changed files with 136 additions and 7 deletions

View file

@ -198,19 +198,19 @@ CURLcode get_url_file_name(char **filename, const char *url, SANITIZEcode *sc)
curl_url_cleanup(uh);
uh = NULL;
if(!uerr) {
int i;
char *pc = NULL, *pc2 = NULL;
for(i = 0; i < 2; i++) {
do {
pc = strrchr(path, '/');
pc2 = strrchr(pc ? pc + 1 : path, '\\');
if(pc2)
pc = pc2;
if(pc && !pc[1] && !i) {
if(pc && !pc[1])
/* if the path ends with slash, try removing the trailing one
and get the last directory part */
*pc = 0;
}
}
else
break;
} while(1);
if(pc) {
/* duplicate the string beyond the slash */