mirror of
https://github.com/curl/curl.git
synced 2026-08-25 20:43:32 +03:00
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:
parent
bae6237c45
commit
8e89646a3d
4 changed files with 136 additions and 7 deletions
|
|
@ -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 */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue