mirror of
https://github.com/moparisthebest/wget
synced 2024-07-03 16:38:41 -04:00
[svn] Quote # and % when creating links to local files.
This commit is contained in:
parent
3f374f6db1
commit
15282415b4
@ -1,3 +1,8 @@
|
|||||||
|
2004-03-04 Hrvoje Niksic <hniksic@xemacs.org>
|
||||||
|
|
||||||
|
* convert.c (local_quote_string): Quote "#" as "%23" and "%" as
|
||||||
|
"%25" when creating links to local files.
|
||||||
|
|
||||||
2004-03-02 David Fritz <zeroxdf@att.net>
|
2004-03-02 David Fritz <zeroxdf@att.net>
|
||||||
|
|
||||||
* mswindows.c (ws_percenttitle): Guard against future changes by
|
* mswindows.c (ws_percenttitle): Guard against future changes by
|
||||||
|
@ -576,49 +576,52 @@ find_fragment (const char *beg, int size, const char **bp, const char **ep)
|
|||||||
"index.html%3Ffoo=bar" would break local browsing, as the latter
|
"index.html%3Ffoo=bar" would break local browsing, as the latter
|
||||||
isn't even recognized as an HTML file! However, converting
|
isn't even recognized as an HTML file! However, converting
|
||||||
"index.html?foo=bar.html" to "index.html%3Ffoo=bar.html" should be
|
"index.html?foo=bar.html" to "index.html%3Ffoo=bar.html" should be
|
||||||
safe for both local and HTTP-served browsing. */
|
safe for both local and HTTP-served browsing.
|
||||||
|
|
||||||
|
We always quote "#" as "%23" and "%" as "%25" because those
|
||||||
|
characters have special meanings in URLs. */
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
local_quote_string (const char *file)
|
local_quote_string (const char *file)
|
||||||
{
|
{
|
||||||
const char *file_sans_qmark;
|
const char *from;
|
||||||
int qm;
|
char *newname, *to;
|
||||||
|
|
||||||
if (!opt.html_extension)
|
char *any = strpbrk (file, "?#%");
|
||||||
|
if (!any)
|
||||||
return html_quote_string (file);
|
return html_quote_string (file);
|
||||||
|
|
||||||
qm = count_char (file, '?');
|
/* Allocate space assuming the worst-case scenario, each character
|
||||||
|
having to be quoted. */
|
||||||
|
to = newname = (char *)alloca (3 * strlen (file) + 1);
|
||||||
|
for (from = file; *from; from++)
|
||||||
|
switch (*from)
|
||||||
|
{
|
||||||
|
case '%':
|
||||||
|
*to++ = '%';
|
||||||
|
*to++ = '2';
|
||||||
|
*to++ = '5';
|
||||||
|
break;
|
||||||
|
case '#':
|
||||||
|
*to++ = '%';
|
||||||
|
*to++ = '2';
|
||||||
|
*to++ = '3';
|
||||||
|
break;
|
||||||
|
case '?':
|
||||||
|
if (opt.html_extension)
|
||||||
|
{
|
||||||
|
*to++ = '%';
|
||||||
|
*to++ = '3';
|
||||||
|
*to++ = 'F';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* fallthrough */
|
||||||
|
default:
|
||||||
|
*to++ = *from;
|
||||||
|
}
|
||||||
|
*to = '\0';
|
||||||
|
|
||||||
if (qm)
|
return html_quote_string (newname);
|
||||||
{
|
|
||||||
const char *from = file;
|
|
||||||
char *to, *newname;
|
|
||||||
|
|
||||||
/* qm * 2 because we replace each question mark with "%3F",
|
|
||||||
i.e. replace one char with three, hence two more. */
|
|
||||||
int fsqlen = strlen (file) + qm * 2;
|
|
||||||
|
|
||||||
to = newname = (char *)alloca (fsqlen + 1);
|
|
||||||
for (; *from; from++)
|
|
||||||
{
|
|
||||||
if (*from != '?')
|
|
||||||
*to++ = *from;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*to++ = '%';
|
|
||||||
*to++ = '3';
|
|
||||||
*to++ = 'F';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assert (to - newname == fsqlen);
|
|
||||||
*to = '\0';
|
|
||||||
|
|
||||||
file_sans_qmark = newname;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
file_sans_qmark = file;
|
|
||||||
|
|
||||||
return html_quote_string (file_sans_qmark);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Book-keeping code for dl_file_url_map, dl_url_file_map,
|
/* Book-keeping code for dl_file_url_map, dl_url_file_map,
|
||||||
|
Loading…
Reference in New Issue
Block a user