X-Git-Url: http://sjero.net/git/?a=blobdiff_plain;f=src%2Furl.c;h=72bb7b90d735c6eca5a73a450dda6b0d4e60a1cf;hb=aa4991b8f74668f04b0ea5e2a73607df3150b257;hp=650c634736ed41c034f1b3bd16bd6365fad7dbc9;hpb=4d7c5e087b2bc82c9f503dff003916d1047903ce;p=wget diff --git a/src/url.c b/src/url.c index 650c6347..72bb7b90 100644 --- a/src/url.c +++ b/src/url.c @@ -1,5 +1,6 @@ /* URL handling. - Copyright (C) 1996-2006 Free Software Foundation, Inc. + Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, + 2004, 2005, 2006, 2007 Free Software Foundation, Inc. This file is part of GNU Wget. @@ -855,7 +856,7 @@ url_parse (const char *url, int *error) /* If we suspect that a transformation has rendered what url_string might return different from URL_ENCODED, rebuild u->url using url_string. */ - u->url = url_string (u, false); + u->url = url_string (u, URL_AUTH_SHOW); if (url_encoded != url) xfree ((char *) url_encoded); @@ -1071,7 +1072,7 @@ sync_path (struct url *u) /* Regenerate u->url as well. */ xfree (u->url); - u->url = url_string (u, false); + u->url = url_string (u, URL_AUTH_SHOW); } /* Mutators. Code in ftp.c insists on changing u->dir and u->file. @@ -1369,7 +1370,7 @@ append_uri_pathel (const char *b, const char *e, bool escaped, || opt.restrict_files_case == restrict_uppercase) { char *q; - for (q = TAIL (dest); *q; ++q) + for (q = TAIL (dest); q < TAIL (dest) + outlen; ++q) { if (opt.restrict_files_case == restrict_lowercase) *q = TOLOWER (*q); @@ -1814,7 +1815,7 @@ uri_merge (const char *base, const char *link) the URL will be quoted. */ char * -url_string (const struct url *url, bool hide_password) +url_string (const struct url *url, enum url_auth_mode auth_mode) { int size; char *result, *p; @@ -1831,13 +1832,16 @@ url_string (const struct url *url, bool hide_password) /* Make sure the user name and password are quoted. */ if (url->user) { - quoted_user = url_escape_allow_passthrough (url->user); - if (url->passwd) + if (auth_mode != URL_AUTH_HIDE) { - if (hide_password) - quoted_passwd = HIDDEN_PASSWORD; - else - quoted_passwd = url_escape_allow_passthrough (url->passwd); + quoted_user = url_escape_allow_passthrough (url->user); + if (url->passwd) + { + if (auth_mode == URL_AUTH_HIDE_PASSWD) + quoted_passwd = HIDDEN_PASSWORD; + else + quoted_passwd = url_escape_allow_passthrough (url->passwd); + } } } @@ -1899,7 +1903,8 @@ url_string (const struct url *url, bool hide_password) if (quoted_user && quoted_user != url->user) xfree (quoted_user); - if (quoted_passwd && !hide_password && quoted_passwd != url->passwd) + if (quoted_passwd && auth_mode == URL_AUTH_SHOW + && quoted_passwd != url->passwd) xfree (quoted_passwd); if (quoted_host != url->host) xfree (quoted_host); @@ -1935,10 +1940,7 @@ getchar_from_escaped_string (const char *str, char *c) if (p[0] == '%') { - if (p[1] == 0) - return 0; /* error: invalid string */ - - if (p[1] == '%') + if (!ISXDIGIT(p[1]) || !ISXDIGIT(p[2])) { *c = '%'; return 1; @@ -1949,8 +1951,13 @@ getchar_from_escaped_string (const char *str, char *c) return 0; /* error: invalid string */ *c = X2DIGITS_TO_NUM (p[1], p[2]); - - return 3; + if (URL_RESERVED_CHAR(*c)) + { + *c = '%'; + return 1; + } + else + return 3; } } else @@ -1967,11 +1974,12 @@ are_urls_equal (const char *u1, const char *u2) const char *p, *q; int pp, qq; char ch1, ch2; + assert(u1 && u2); p = u1; q = u2; - while (*p + while (*p && *q && (pp = getchar_from_escaped_string (p, &ch1)) && (qq = getchar_from_escaped_string (q, &ch2)) && (TOLOWER(ch1) == TOLOWER(ch2))) @@ -2085,6 +2093,7 @@ test_append_uri_pathel() append_string (test_array[i].original_url, &dest); append_uri_pathel (p, p + strlen(p), test_array[i].escaped, &dest); + append_char ('\0', &dest); mu_assert ("test_append_uri_pathel: wrong result", strcmp (dest.base, test_array[i].expected_result) == 0); @@ -2106,6 +2115,8 @@ test_are_urls_equal() { "http://www.adomain.com/apath/", "http://www.adomain.com/anotherpath/", false }, { "http://www.adomain.com/apath/", "http://www.anotherdomain.com/path/", false }, { "http://www.adomain.com/~path/", "http://www.adomain.com/%7epath/", true }, + { "http://www.adomain.com/longer-path/", "http://www.adomain.com/path/", false }, + { "http://www.adomain.com/path%2f", "http://www.adomain.com/path/", false }, }; for (i = 0; i < sizeof(test_array)/sizeof(test_array[0]); ++i)