mirror of
https://github.com/moparisthebest/wget
synced 2024-07-03 16:38:41 -04:00
[svn] Added support for --restrict-file-names=lowercase and --restrict-file-names=uppercase.
This commit is contained in:
parent
9d9f134fdf
commit
c1cb70ecd0
@ -1,3 +1,19 @@
|
|||||||
|
2006-06-13 Mauro Tortonesi <mauro@ferrara.linux.it>
|
||||||
|
|
||||||
|
* options.h (struct options): Introduced member restrict_files_case to
|
||||||
|
keep track of preferences on character case restrictions for
|
||||||
|
filenames.
|
||||||
|
|
||||||
|
* init.c: Modified defaults and cmd_spec_restrict_file_names to
|
||||||
|
support character case restrictions for filenames. Added
|
||||||
|
test_cmd_spec_restrict_file_names unit test.
|
||||||
|
|
||||||
|
* url.c: Modified append_uri_pathel to support character case
|
||||||
|
restrictions for filenames. Added test_append_uri_pathel unit test.
|
||||||
|
|
||||||
|
* test.c: Added test_cmd_spec_restrict_file_names and
|
||||||
|
test_append_uri_pathel to the list of unit tests to run.
|
||||||
|
|
||||||
2006-06-12 Mauro Tortonesi <mauro@ferrara.linux.it>
|
2006-06-12 Mauro Tortonesi <mauro@ferrara.linux.it>
|
||||||
|
|
||||||
* retr.c (retrieve_from_file): Use retrieve_tree and automatically
|
* retr.c (retrieve_from_file): Use retrieve_tree and automatically
|
||||||
|
105
src/init.c
105
src/init.c
@ -54,6 +54,10 @@ so, delete this exception statement from your version. */
|
|||||||
#include "http.h" /* for http_cleanup */
|
#include "http.h" /* for http_cleanup */
|
||||||
#include "retr.h" /* for output_stream */
|
#include "retr.h" /* for output_stream */
|
||||||
|
|
||||||
|
#ifdef TESTING
|
||||||
|
#include "test.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/* We want tilde expansion enabled only when reading `.wgetrc' lines;
|
/* We want tilde expansion enabled only when reading `.wgetrc' lines;
|
||||||
otherwise, it will be performed by the shell. This variable will
|
otherwise, it will be performed by the shell. This variable will
|
||||||
be set by the wgetrc-reading function. */
|
be set by the wgetrc-reading function. */
|
||||||
@ -314,6 +318,7 @@ defaults (void)
|
|||||||
opt.restrict_files_os = restrict_windows;
|
opt.restrict_files_os = restrict_windows;
|
||||||
#endif
|
#endif
|
||||||
opt.restrict_files_ctrl = true;
|
opt.restrict_files_ctrl = true;
|
||||||
|
opt.restrict_files_case = restrict_no_case_restriction;
|
||||||
|
|
||||||
opt.content_disposition = true;
|
opt.content_disposition = true;
|
||||||
}
|
}
|
||||||
@ -1178,40 +1183,47 @@ cmd_spec_restrict_file_names (const char *com, const char *val, void *place_igno
|
|||||||
{
|
{
|
||||||
int restrict_os = opt.restrict_files_os;
|
int restrict_os = opt.restrict_files_os;
|
||||||
int restrict_ctrl = opt.restrict_files_ctrl;
|
int restrict_ctrl = opt.restrict_files_ctrl;
|
||||||
|
int restrict_case = opt.restrict_files_case;
|
||||||
|
|
||||||
const char *end = strchr (val, ',');
|
const char *end;
|
||||||
if (!end)
|
|
||||||
end = val + strlen (val);
|
|
||||||
|
|
||||||
#define VAL_IS(string_literal) BOUNDED_EQUAL (val, end, string_literal)
|
#define VAL_IS(string_literal) BOUNDED_EQUAL (val, end, string_literal)
|
||||||
|
|
||||||
if (VAL_IS ("unix"))
|
do
|
||||||
restrict_os = restrict_unix;
|
|
||||||
else if (VAL_IS ("windows"))
|
|
||||||
restrict_os = restrict_windows;
|
|
||||||
else if (VAL_IS ("nocontrol"))
|
|
||||||
restrict_ctrl = 0;
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
err:
|
end = strchr (val, ',');
|
||||||
fprintf (stderr,
|
if (!end)
|
||||||
_("%s: %s: Invalid restriction `%s', use `unix' or `windows'.\n"),
|
end = val + strlen (val);
|
||||||
exec_name, com, val);
|
|
||||||
return false;
|
if (VAL_IS ("unix"))
|
||||||
|
restrict_os = restrict_unix;
|
||||||
|
else if (VAL_IS ("windows"))
|
||||||
|
restrict_os = restrict_windows;
|
||||||
|
else if (VAL_IS ("lowercase"))
|
||||||
|
restrict_case = restrict_lowercase;
|
||||||
|
else if (VAL_IS ("uppercase"))
|
||||||
|
restrict_case = restrict_uppercase;
|
||||||
|
else if (VAL_IS ("nocontrol"))
|
||||||
|
restrict_ctrl = false;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf (stderr,
|
||||||
|
_("%s: %s: Invalid restriction `%s', use [unix|windows],[lowercase|uppercase],[nocontrol].\n"),
|
||||||
|
exec_name, com, val);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*end)
|
||||||
|
val = end + 1;
|
||||||
}
|
}
|
||||||
|
while (*val && *end);
|
||||||
|
|
||||||
#undef VAL_IS
|
#undef VAL_IS
|
||||||
|
|
||||||
if (*end)
|
|
||||||
{
|
|
||||||
if (!strcmp (end + 1, "nocontrol"))
|
|
||||||
restrict_ctrl = false;
|
|
||||||
else
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
opt.restrict_files_os = restrict_os;
|
opt.restrict_files_os = restrict_os;
|
||||||
opt.restrict_files_ctrl = restrict_ctrl;
|
opt.restrict_files_ctrl = restrict_ctrl;
|
||||||
|
opt.restrict_files_case = restrict_case;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1492,3 +1504,50 @@ cleanup (void)
|
|||||||
xfree_null (opt.passwd);
|
xfree_null (opt.passwd);
|
||||||
#endif /* DEBUG_MALLOC */
|
#endif /* DEBUG_MALLOC */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Unit testing routines. */
|
||||||
|
|
||||||
|
#ifdef TESTING
|
||||||
|
|
||||||
|
const char *
|
||||||
|
test_cmd_spec_restrict_file_names()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
struct {
|
||||||
|
char *val;
|
||||||
|
int expected_restrict_files_os;
|
||||||
|
int expected_restrict_files_ctrl;
|
||||||
|
int expected_restrict_files_case;
|
||||||
|
bool result;
|
||||||
|
} test_array[] = {
|
||||||
|
{ "windows", restrict_windows, true, restrict_no_case_restriction, true },
|
||||||
|
{ "windows,", restrict_windows, true, restrict_no_case_restriction, true },
|
||||||
|
{ "windows,lowercase", restrict_windows, true, restrict_lowercase, true },
|
||||||
|
{ "unix,nocontrol,lowercase,", restrict_unix, false, restrict_lowercase, true },
|
||||||
|
};
|
||||||
|
|
||||||
|
for (i = 0; i < sizeof(test_array)/sizeof(test_array[0]); ++i)
|
||||||
|
{
|
||||||
|
bool res;
|
||||||
|
|
||||||
|
defaults();
|
||||||
|
res = cmd_spec_restrict_file_names ("dummy", test_array[i].val, NULL);
|
||||||
|
|
||||||
|
/*
|
||||||
|
fprintf (stderr, "test_cmd_spec_restrict_file_names: TEST %d\n", i); fflush (stderr);
|
||||||
|
fprintf (stderr, "opt.restrict_files_os: %d\n", opt.restrict_files_os); fflush (stderr);
|
||||||
|
fprintf (stderr, "opt.restrict_files_ctrl: %d\n", opt.restrict_files_ctrl); fflush (stderr);
|
||||||
|
fprintf (stderr, "opt.restrict_files_case: %d\n", opt.restrict_files_case); fflush (stderr);
|
||||||
|
*/
|
||||||
|
mu_assert ("test_cmd_spec_restrict_file_names: wrong result",
|
||||||
|
res == test_array[i].result
|
||||||
|
&& opt.restrict_files_os == test_array[i].expected_restrict_files_os
|
||||||
|
&& opt.restrict_files_ctrl == test_array[i].expected_restrict_files_ctrl
|
||||||
|
&& opt.restrict_files_case == test_array[i].expected_restrict_files_case);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* TESTING */
|
||||||
|
|
||||||
|
@ -203,6 +203,11 @@ struct options
|
|||||||
bool restrict_files_ctrl; /* non-zero if control chars in URLs
|
bool restrict_files_ctrl; /* non-zero if control chars in URLs
|
||||||
are restricted from appearing in
|
are restricted from appearing in
|
||||||
generated file names. */
|
generated file names. */
|
||||||
|
enum {
|
||||||
|
restrict_no_case_restriction,
|
||||||
|
restrict_lowercase,
|
||||||
|
restrict_uppercase
|
||||||
|
} restrict_files_case; /* file name case restriction. */
|
||||||
|
|
||||||
bool strict_comments; /* whether strict SGML comments are
|
bool strict_comments; /* whether strict SGML comments are
|
||||||
enforced. */
|
enforced. */
|
||||||
|
@ -38,6 +38,8 @@ so, delete this exception statement from your version. */
|
|||||||
const char *test_parse_content_disposition();
|
const char *test_parse_content_disposition();
|
||||||
const char *test_subdir_p();
|
const char *test_subdir_p();
|
||||||
const char *test_dir_matches_p();
|
const char *test_dir_matches_p();
|
||||||
|
const char *test_cmd_spec_restrict_file_names();
|
||||||
|
const char *test_append_uri_pathel();
|
||||||
|
|
||||||
int tests_run;
|
int tests_run;
|
||||||
|
|
||||||
@ -47,6 +49,8 @@ all_tests()
|
|||||||
mu_run_test (test_parse_content_disposition);
|
mu_run_test (test_parse_content_disposition);
|
||||||
mu_run_test (test_subdir_p);
|
mu_run_test (test_subdir_p);
|
||||||
mu_run_test (test_dir_matches_p);
|
mu_run_test (test_dir_matches_p);
|
||||||
|
mu_run_test (test_cmd_spec_restrict_file_names);
|
||||||
|
mu_run_test (test_append_uri_pathel);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
54
src/url.c
54
src/url.c
@ -43,6 +43,10 @@ so, delete this exception statement from your version. */
|
|||||||
#include "url.h"
|
#include "url.h"
|
||||||
#include "host.h" /* for is_valid_ipv6_address */
|
#include "host.h" /* for is_valid_ipv6_address */
|
||||||
|
|
||||||
|
#ifdef TESTING
|
||||||
|
#include "test.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
scm_disabled = 1, /* for https when OpenSSL fails to init. */
|
scm_disabled = 1, /* for https when OpenSSL fails to init. */
|
||||||
scm_has_params = 2, /* whether scheme has ;params */
|
scm_has_params = 2, /* whether scheme has ;params */
|
||||||
@ -1360,6 +1364,21 @@ append_uri_pathel (const char *b, const char *e, bool escaped,
|
|||||||
}
|
}
|
||||||
assert (q - TAIL (dest) == outlen);
|
assert (q - TAIL (dest) == outlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Perform inline case transformation if required. */
|
||||||
|
if (opt.restrict_files_case == restrict_lowercase
|
||||||
|
|| opt.restrict_files_case == restrict_uppercase)
|
||||||
|
{
|
||||||
|
char *q;
|
||||||
|
for (q = TAIL (dest); *q; ++q)
|
||||||
|
{
|
||||||
|
if (opt.restrict_files_case == restrict_lowercase)
|
||||||
|
*q = TOLOWER (*q);
|
||||||
|
else
|
||||||
|
*q = TOUPPER (*q);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TAIL_INCR (dest, outlen);
|
TAIL_INCR (dest, outlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1984,3 +2003,38 @@ test_path_simplify (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef TESTING
|
||||||
|
|
||||||
|
const char *
|
||||||
|
test_append_uri_pathel()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
struct {
|
||||||
|
char *original_url;
|
||||||
|
char *input;
|
||||||
|
bool escaped;
|
||||||
|
char *expected_result;
|
||||||
|
} test_array[] = {
|
||||||
|
{ "http://www.yoyodyne.com/path/", "somepage.html", false, "http://www.yoyodyne.com/path/somepage.html" },
|
||||||
|
};
|
||||||
|
|
||||||
|
for (i = 0; i < sizeof(test_array)/sizeof(test_array[0]); ++i)
|
||||||
|
{
|
||||||
|
struct growable dest;
|
||||||
|
const char *p = test_array[i].input;
|
||||||
|
|
||||||
|
memset (&dest, 0, sizeof (dest));
|
||||||
|
|
||||||
|
append_string (test_array[i].original_url, &dest);
|
||||||
|
append_uri_pathel (p, p + strlen(p), test_array[i].escaped, &dest);
|
||||||
|
|
||||||
|
mu_assert ("test_append_uri_pathel: wrong result",
|
||||||
|
strcmp (dest.base, test_array[i].expected_result) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* TESTING */
|
||||||
|
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
2006-06-13 Mauro Tortonesi <mauro@ferrara.linux.it>
|
||||||
|
|
||||||
|
* Test9.px: Added test for --restrict-file-names=lowercase option.
|
||||||
|
|
||||||
|
* Test10.px: Added test for --restrict-file-names=uppercase option.
|
||||||
|
|
||||||
2006-05-26 Mauro Tortonesi <mauro@ferrara.linux.it>
|
2006-05-26 Mauro Tortonesi <mauro@ferrara.linux.it>
|
||||||
|
|
||||||
* HTTPServer.pm: Added synchronization between client and server
|
* HTTPServer.pm: Added synchronization between client and server
|
||||||
|
55
tests/Test10.px
Executable file
55
tests/Test10.px
Executable file
@ -0,0 +1,55 @@
|
|||||||
|
#!/usr/bin/perl -w
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
|
||||||
|
use HTTPTest;
|
||||||
|
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
my $mainpage = <<EOF;
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Some Page Title</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>
|
||||||
|
Some text...
|
||||||
|
</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# code, msg, headers, content
|
||||||
|
my %urls = (
|
||||||
|
'/SomePage.html' => {
|
||||||
|
code => "200",
|
||||||
|
msg => "Dontcare",
|
||||||
|
headers => {
|
||||||
|
"Content-type" => "text/html",
|
||||||
|
},
|
||||||
|
content => $mainpage,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
my $cmdline = "wget --restrict-file-names=uppercase http://localhost:8080/SomePage.html";
|
||||||
|
|
||||||
|
my $expected_error_code = 0;
|
||||||
|
|
||||||
|
my %expected_downloaded_files = (
|
||||||
|
'SOMEPAGE.HTML' => {
|
||||||
|
content => $mainpage,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
my $the_test = HTTPTest->new (name => "Test9",
|
||||||
|
input => \%urls,
|
||||||
|
cmdline => $cmdline,
|
||||||
|
errcode => $expected_error_code,
|
||||||
|
output => \%expected_downloaded_files);
|
||||||
|
$the_test->run();
|
||||||
|
|
||||||
|
# vim: et ts=4 sw=4
|
||||||
|
|
@ -49,7 +49,7 @@ my %urls = (
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
my $cmdline = "wget -Sd --spider -r http://localhost:8080/";
|
my $cmdline = "wget --spider -r http://localhost:8080/";
|
||||||
|
|
||||||
my $expected_error_code = 0;
|
my $expected_error_code = 0;
|
||||||
|
|
||||||
|
55
tests/Test9.px
Executable file
55
tests/Test9.px
Executable file
@ -0,0 +1,55 @@
|
|||||||
|
#!/usr/bin/perl -w
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
|
||||||
|
use HTTPTest;
|
||||||
|
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
my $mainpage = <<EOF;
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Some Page Title</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>
|
||||||
|
Some text...
|
||||||
|
</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# code, msg, headers, content
|
||||||
|
my %urls = (
|
||||||
|
'/SomePage.html' => {
|
||||||
|
code => "200",
|
||||||
|
msg => "Dontcare",
|
||||||
|
headers => {
|
||||||
|
"Content-type" => "text/html",
|
||||||
|
},
|
||||||
|
content => $mainpage,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
my $cmdline = "wget --restrict-file-names=lowercase http://localhost:8080/SomePage.html";
|
||||||
|
|
||||||
|
my $expected_error_code = 0;
|
||||||
|
|
||||||
|
my %expected_downloaded_files = (
|
||||||
|
'somepage.html' => {
|
||||||
|
content => $mainpage,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
my $the_test = HTTPTest->new (name => "Test9",
|
||||||
|
input => \%urls,
|
||||||
|
cmdline => $cmdline,
|
||||||
|
errcode => $expected_error_code,
|
||||||
|
output => \%expected_downloaded_files);
|
||||||
|
$the_test->run();
|
||||||
|
|
||||||
|
# vim: et ts=4 sw=4
|
||||||
|
|
Loading…
Reference in New Issue
Block a user