mirror of
https://github.com/moparisthebest/wget
synced 2024-07-03 16:38:41 -04:00
[svn] Fix -P in case HTTP Content-Disposition header is present.
This commit is contained in:
parent
92b2323253
commit
14ee3a6c03
@ -1,3 +1,8 @@
|
||||
2006-12-27 Mauro Tortonesi <mauro@ferrara.linux.it>
|
||||
|
||||
* http.c (parse_content_disposition): Consider directory prefix, if
|
||||
specified.
|
||||
|
||||
2006-11-21 Hrvoje Niksic <hniksic@xemacs.org>
|
||||
|
||||
* retr.c (retrieve_from_file): Ditto.
|
||||
|
36
src/http.c
36
src/http.c
@ -966,6 +966,24 @@ parse_content_disposition (const char *hdr, char **filename)
|
||||
value.b = 1 + (last_slash ? last_slash : last_bs);
|
||||
if (value.b == value.e)
|
||||
continue;
|
||||
/* Start with the directory prefix, if specified. */
|
||||
if (opt.dir_prefix)
|
||||
{
|
||||
int prefix_length = strlen (opt.dir_prefix);
|
||||
bool add_slash = (opt.dir_prefix[prefix_length - 1] != '/');
|
||||
int total_length;
|
||||
|
||||
if (add_slash)
|
||||
++prefix_length;
|
||||
total_length = prefix_length + (value.e - value.b);
|
||||
*filename = xmalloc (total_length + 1);
|
||||
strcpy (*filename, opt.dir_prefix);
|
||||
if (add_slash)
|
||||
(*filename)[prefix_length - 1] = '/';
|
||||
memcpy (*filename + prefix_length, value.b, (value.e - value.b));
|
||||
(*filename)[total_length] = '\0';
|
||||
}
|
||||
else
|
||||
*filename = strdupdelim (value.b, value.e);
|
||||
return true;
|
||||
}
|
||||
@ -3027,19 +3045,27 @@ test_parse_content_disposition()
|
||||
int i;
|
||||
struct {
|
||||
char *hdrval;
|
||||
char *opt_dir_prefix;
|
||||
char *filename;
|
||||
bool result;
|
||||
} test_array[] = {
|
||||
{ "filename=\"file.ext\"", "file.ext", true },
|
||||
{ "attachment; filename=\"file.ext\"", "file.ext", true },
|
||||
{ "attachment; filename=\"file.ext\"; dummy", "file.ext", true },
|
||||
{ "attachment", NULL, false },
|
||||
{ "filename=\"file.ext\"", NULL, "file.ext", true },
|
||||
{ "filename=\"file.ext\"", "somedir", "somedir/file.ext", true },
|
||||
{ "attachment; filename=\"file.ext\"", NULL, "file.ext", true },
|
||||
{ "attachment; filename=\"file.ext\"", "somedir", "somedir/file.ext", true },
|
||||
{ "attachment; filename=\"file.ext\"; dummy", NULL, "file.ext", true },
|
||||
{ "attachment; filename=\"file.ext\"; dummy", "somedir", "somedir/file.ext", true },
|
||||
{ "attachment", NULL, NULL, false },
|
||||
{ "attachment", "somedir", NULL, false },
|
||||
};
|
||||
|
||||
for (i = 0; i < sizeof(test_array)/sizeof(test_array[0]); ++i)
|
||||
{
|
||||
char *filename;
|
||||
bool res = parse_content_disposition (test_array[i].hdrval, &filename);
|
||||
bool res;
|
||||
|
||||
opt.dir_prefix = test_array[i].opt_dir_prefix;
|
||||
res = parse_content_disposition (test_array[i].hdrval, &filename);
|
||||
|
||||
mu_assert ("test_parse_content_disposition: wrong result",
|
||||
res == test_array[i].result
|
||||
|
Loading…
Reference in New Issue
Block a user