From: Micah Cowan Date: Tue, 28 Jul 2009 06:41:26 +0000 (-0700) Subject: --restrict-file-names=ascii X-Git-Tag: v1.13~288 X-Git-Url: http://sjero.net/git/?p=wget;a=commitdiff_plain;h=fb0946c7fc6f1831894e8fd67389c0bc74a387b8 --restrict-file-names=ascii --- diff --git a/src/ChangeLog b/src/ChangeLog index 7c7e4e97..afac4339 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,14 @@ +2009-07-27 Micah Cowan + + * options.h (struct options): Added restrict_files_nonascii + boolean field. + + * url.c (FILE_CHAR_TEST): Add check for chars outside the ASCII + range. + + * init.c (defaults): Add restrict_files_nonascii to initialization. + (cmd_spec_restrict_file_names): Allow parsing of "ascii" keyword. + 2009-07-27 Marcel Telka * iri.c (do_conversion): Typo: invalide -> invalid diff --git a/src/init.c b/src/init.c index 172b54b5..5a4bbe50 100644 --- a/src/init.c +++ b/src/init.c @@ -329,6 +329,7 @@ defaults (void) opt.restrict_files_os = restrict_unix; #endif opt.restrict_files_ctrl = true; + opt.restrict_files_nonascii = false; opt.restrict_files_case = restrict_no_case_restriction; opt.max_redirect = 20; @@ -1275,6 +1276,7 @@ cmd_spec_restrict_file_names (const char *com, const char *val, void *place_igno int restrict_os = opt.restrict_files_os; int restrict_ctrl = opt.restrict_files_ctrl; int restrict_case = opt.restrict_files_case; + int restrict_nonascii = opt.restrict_files_nonascii; const char *end; @@ -1285,7 +1287,7 @@ cmd_spec_restrict_file_names (const char *com, const char *val, void *place_igno end = strchr (val, ','); if (!end) end = val + strlen (val); - + if (VAL_IS ("unix")) restrict_os = restrict_unix; else if (VAL_IS ("windows")) @@ -1296,10 +1298,13 @@ cmd_spec_restrict_file_names (const char *com, const char *val, void *place_igno restrict_case = restrict_uppercase; else if (VAL_IS ("nocontrol")) restrict_ctrl = false; + else if (VAL_IS ("ascii")) + restrict_nonascii = true; else { - fprintf (stderr, - _("%s: %s: Invalid restriction %s, use [unix|windows],[lowercase|uppercase],[nocontrol].\n"), + fprintf (stderr, _("\ +%s: %s: Invalid restriction %s,\n\ + use [unix|windows],[lowercase|uppercase],[nocontrol],[ascii].\n"), exec_name, com, quote (val)); return false; } @@ -1314,6 +1319,7 @@ cmd_spec_restrict_file_names (const char *com, const char *val, void *place_igno opt.restrict_files_os = restrict_os; opt.restrict_files_ctrl = restrict_ctrl; opt.restrict_files_case = restrict_case; + opt.restrict_files_nonascii = restrict_nonascii; return true; } diff --git a/src/options.h b/src/options.h index 382fe312..cc0d20e6 100644 --- a/src/options.h +++ b/src/options.h @@ -209,6 +209,8 @@ struct options bool restrict_files_ctrl; /* non-zero if control chars in URLs are restricted from appearing in generated file names. */ + bool restrict_files_nonascii; /* non-zero if bytes with values greater + than 127 are restricted. */ enum { restrict_no_case_restriction, restrict_lowercase, diff --git a/src/url.c b/src/url.c index 2453157a..afc31811 100644 --- a/src/url.c +++ b/src/url.c @@ -1291,7 +1291,9 @@ enum { filechr_control = 4 /* a control character, e.g. 0-31 */ }; -#define FILE_CHAR_TEST(c, mask) (filechr_table[(unsigned char)(c)] & (mask)) +#define FILE_CHAR_TEST(c, mask) \ + ((opt.restrict_files_nonascii && !c_isascii ((unsigned char)(c))) || \ + (filechr_table[(unsigned char)(c)] & (mask))) /* Shorthands for the table: */ #define U filechr_not_unix diff --git a/tests/ChangeLog b/tests/ChangeLog index d1a8af8b..785b36e4 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,9 @@ +2009-07-27 Micah Cowan + + * Test-restrict-ascii.px: New. + + * run-px: Added Test-restrict-ascii.px. + 2009-07-26 Micah Cowan * Test-ftp-iri.px, Test-ftp-iri-fallback.px, diff --git a/tests/Test-restrict-ascii.px b/tests/Test-restrict-ascii.px new file mode 100755 index 00000000..ec76349d --- /dev/null +++ b/tests/Test-restrict-ascii.px @@ -0,0 +1,69 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use HTTPTest; + +# This program tests that --restrict-file-names=ascii can be used to +# ensure that all high-valued bytes are escaped. The sample filename was +# chosen because in former versions of Wget, one could either choose not +# to escape any portion of the UTF-8 filename via +# --restrict-file-names=nocontrol (which would only be helpful if one +# was _on_ a UTF-8 system), or else Wget would escape _portions_ of +# characters, leaving irrelevant "latin1"-looking characters combined +# with percent-encoded "control" characters, instead of encoding all the +# bytes of an entire non-ASCII UTF-8 character. + +############################################################################### + +# "gnosis" in UTF-8 greek. +my $gnosis = '%CE%B3%CE%BD%CF%89%CF%83%CE%B9%CF%82'; + +my $mainpage = < + + Some Page Title + + +

+ Some text... +

+ + +EOF + +# code, msg, headers, content +my %urls = ( + "/$gnosis.html" => { + code => "200", + msg => "Dontcare", + headers => { + "Content-type" => "text/html", + }, + content => $mainpage, + }, +); + +my $cmdline = $WgetTest::WGETPATH . " --restrict-file-names=ascii " + . "http://localhost:{{port}}/${gnosis}.html"; + +my $expected_error_code = 0; + +my %expected_downloaded_files = ( + "${gnosis}.html" => { + content => $mainpage, + }, +); + +############################################################################### + +my $the_test = HTTPTest->new (name => "Test-restrict-ascii", + input => \%urls, + cmdline => $cmdline, + errcode => $expected_error_code, + output => \%expected_downloaded_files); +exit $the_test->run(); + +# vim: et ts=4 sw=4 + diff --git a/tests/run-px b/tests/run-px index b480f141..17a52cdf 100755 --- a/tests/run-px +++ b/tests/run-px @@ -60,6 +60,7 @@ my @tests = ( 'Test-O-nonexisting.px', 'Test-O.px', 'Test-O-nc.px', + 'Test-restrict-ascii.px', 'Test-Restrict-Lowercase.px', 'Test-Restrict-Uppercase.px', 'Test--spider-fail.px',