curl/get_url_file_name: use libcurl URL parser
To avoid URL tricks, use the URL parser for this. This update changes curl's behavior slightly in that it will ignore the possible query part from the URL and only use the file name from the actual path from the URL. I consider it a bugfix. "curl -O localhost/name?giveme-giveme" will now save the output in the local file named 'name' Updated test 1210 to verify Assisted-by: Jay Satiro Closes #9684
This commit is contained in:
parent
c96462addc
commit
671adfa493
@ -149,61 +149,65 @@ CURLcode add_file_name_to_url(CURL *curl, char **inurlp, const char *filename)
|
|||||||
CURLcode get_url_file_name(char **filename, const char *url)
|
CURLcode get_url_file_name(char **filename, const char *url)
|
||||||
{
|
{
|
||||||
const char *pc, *pc2;
|
const char *pc, *pc2;
|
||||||
|
CURLU *uh = curl_url();
|
||||||
|
char *path = NULL;
|
||||||
|
|
||||||
|
if(!uh)
|
||||||
|
return CURLE_OUT_OF_MEMORY;
|
||||||
|
|
||||||
*filename = NULL;
|
*filename = NULL;
|
||||||
|
|
||||||
/* Find and get the remote file name */
|
if(!curl_url_set(uh, CURLUPART_URL, url, CURLU_GUESS_SCHEME) &&
|
||||||
pc = strstr(url, "://");
|
!curl_url_get(uh, CURLUPART_PATH, &path, 0)) {
|
||||||
if(pc)
|
curl_url_cleanup(uh);
|
||||||
pc += 3;
|
|
||||||
else
|
|
||||||
pc = url;
|
|
||||||
|
|
||||||
pc2 = strrchr(pc, '\\');
|
pc = strrchr(path, '/');
|
||||||
pc = strrchr(pc, '/');
|
pc2 = strrchr(pc ? pc + 1 : path, '\\');
|
||||||
if(pc2 && (!pc || pc < pc2))
|
if(pc2)
|
||||||
pc = pc2;
|
pc = pc2;
|
||||||
|
|
||||||
if(pc)
|
if(pc)
|
||||||
/* duplicate the string beyond the slash */
|
/* duplicate the string beyond the slash */
|
||||||
pc++;
|
pc++;
|
||||||
else
|
else
|
||||||
/* no slash => empty string */
|
/* no slash => empty string */
|
||||||
pc = "";
|
pc = "";
|
||||||
|
|
||||||
*filename = strdup(pc);
|
*filename = strdup(pc);
|
||||||
if(!*filename)
|
curl_free(path);
|
||||||
return CURLE_OUT_OF_MEMORY;
|
if(!*filename)
|
||||||
|
return CURLE_OUT_OF_MEMORY;
|
||||||
|
|
||||||
#if defined(MSDOS) || defined(WIN32)
|
#if defined(MSDOS) || defined(WIN32)
|
||||||
{
|
{
|
||||||
char *sanitized;
|
char *sanitized;
|
||||||
SANITIZEcode sc = sanitize_file_name(&sanitized, *filename, 0);
|
SANITIZEcode sc = sanitize_file_name(&sanitized, *filename, 0);
|
||||||
Curl_safefree(*filename);
|
Curl_safefree(*filename);
|
||||||
if(sc)
|
if(sc)
|
||||||
return CURLE_URL_MALFORMAT;
|
return CURLE_URL_MALFORMAT;
|
||||||
*filename = sanitized;
|
*filename = sanitized;
|
||||||
}
|
}
|
||||||
#endif /* MSDOS || WIN32 */
|
#endif /* MSDOS || WIN32 */
|
||||||
|
|
||||||
/* in case we built debug enabled, we allow an environment variable
|
/* in case we built debug enabled, we allow an environment variable
|
||||||
* named CURL_TESTDIR to prefix the given file name to put it into a
|
* named CURL_TESTDIR to prefix the given file name to put it into a
|
||||||
* specific directory
|
* specific directory
|
||||||
*/
|
*/
|
||||||
#ifdef DEBUGBUILD
|
#ifdef DEBUGBUILD
|
||||||
{
|
{
|
||||||
char *tdir = curlx_getenv("CURL_TESTDIR");
|
char *tdir = curlx_getenv("CURL_TESTDIR");
|
||||||
if(tdir) {
|
if(tdir) {
|
||||||
char buffer[512]; /* suitably large */
|
char *alt = aprintf("%s/%s", tdir, *filename);
|
||||||
msnprintf(buffer, sizeof(buffer), "%s/%s", tdir, *filename);
|
Curl_safefree(*filename);
|
||||||
Curl_safefree(*filename);
|
*filename = alt;
|
||||||
*filename = strdup(buffer); /* clone the buffer */
|
curl_free(tdir);
|
||||||
curl_free(tdir);
|
if(!*filename)
|
||||||
if(!*filename)
|
return CURLE_OUT_OF_MEMORY;
|
||||||
return CURLE_OUT_OF_MEMORY;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
return CURLE_OK;
|
||||||
return CURLE_OK;
|
}
|
||||||
|
curl_url_cleanup(uh);
|
||||||
|
return CURLE_URL_MALFORMAT;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,7 +39,7 @@ HTTP GET with -J without Content-Disposition
|
|||||||
CURL_TESTDIR=%PWD/log
|
CURL_TESTDIR=%PWD/log
|
||||||
</setenv>
|
</setenv>
|
||||||
<command option="no-output,no-include">
|
<command option="no-output,no-include">
|
||||||
http://%HOSTIP:%HTTPPORT/%TESTNUMBER -J -O
|
http://%HOSTIP:%HTTPPORT/%TESTNUMBER?junk -J -O
|
||||||
</command>
|
</command>
|
||||||
</client>
|
</client>
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ http://%HOSTIP:%HTTPPORT/%TESTNUMBER -J -O
|
|||||||
# Verify data after the test has been "shot"
|
# Verify data after the test has been "shot"
|
||||||
<verify>
|
<verify>
|
||||||
<protocol>
|
<protocol>
|
||||||
GET /%TESTNUMBER HTTP/1.1
|
GET /%TESTNUMBER?junk HTTP/1.1
|
||||||
Host: %HOSTIP:%HTTPPORT
|
Host: %HOSTIP:%HTTPPORT
|
||||||
User-Agent: curl/%VERSION
|
User-Agent: curl/%VERSION
|
||||||
Accept: */*
|
Accept: */*
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user