mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05:00
Bug 744: Make removal of double slashes more protocol specific
Add a boolean protocol flag which says whether "//" in the path part of an URI can be safely substituted with "/". Be conservative and enable it only for file://, ftp:// and nntp[s]://. Other can be turned on later, if needed. Generalizes the fix from 58b3b1e75239fac7f48d54609b4033c228d6a5da.
This commit is contained in:
parent
fad6cd9ba2
commit
ee159e2bf9
@ -52,34 +52,35 @@ struct protocol_backend {
|
|||||||
unsigned int need_slash_after_host:1;
|
unsigned int need_slash_after_host:1;
|
||||||
unsigned int free_syntax:1;
|
unsigned int free_syntax:1;
|
||||||
unsigned int need_ssl:1;
|
unsigned int need_ssl:1;
|
||||||
|
unsigned int keep_double_slashes:1;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct protocol_backend protocol_backends[] = {
|
static const struct protocol_backend protocol_backends[] = {
|
||||||
{ "about", 0, about_protocol_handler, 0, 0, 1, 0 },
|
{ "about", 0, about_protocol_handler, 0, 0, 1, 0, 1 },
|
||||||
{ "bittorrent", 0, bittorrent_protocol_handler, 0, 0, 1, 0 },
|
{ "bittorrent", 0, bittorrent_protocol_handler, 0, 0, 1, 0, 1 },
|
||||||
{ "data", 0, data_protocol_handler, 0, 0, 1, 0 },
|
{ "data", 0, data_protocol_handler, 0, 0, 1, 0, 1 },
|
||||||
{ "file", 0, file_protocol_handler, 1, 0, 0, 0 },
|
{ "file", 0, file_protocol_handler, 1, 0, 0, 0, 0 },
|
||||||
{ "finger", 79, finger_protocol_handler, 1, 1, 0, 0 },
|
{ "finger", 79, finger_protocol_handler, 1, 1, 0, 0, 1 },
|
||||||
{ "fsp", 21, fsp_protocol_handler, 1, 1, 0, 0 },
|
{ "fsp", 21, fsp_protocol_handler, 1, 1, 0, 0, 1 },
|
||||||
{ "ftp", 21, ftp_protocol_handler, 1, 1, 0, 0 },
|
{ "ftp", 21, ftp_protocol_handler, 1, 1, 0, 0, 0 },
|
||||||
{ "gopher", 70, gopher_protocol_handler, 1, 1, 0, 0 },
|
{ "gopher", 70, gopher_protocol_handler, 1, 1, 0, 0, 1 },
|
||||||
{ "http", 80, http_protocol_handler, 1, 1, 0, 0 },
|
{ "http", 80, http_protocol_handler, 1, 1, 0, 0, 1 },
|
||||||
{ "https", 443, https_protocol_handler, 1, 1, 0, 1 },
|
{ "https", 443, https_protocol_handler, 1, 1, 0, 1, 1 },
|
||||||
{ "javascript", 0, NULL, 0, 0, 1, 0 },
|
{ "javascript", 0, NULL, 0, 0, 1, 0, 1 },
|
||||||
{ "news", 0, news_protocol_handler, 0, 0, 1, 0 },
|
{ "news", 0, news_protocol_handler, 0, 0, 1, 0, 1 },
|
||||||
{ "nntp", 119, nntp_protocol_handler, 1, 1, 0, 0 },
|
{ "nntp", 119, nntp_protocol_handler, 1, 1, 0, 0, 0 },
|
||||||
{ "nntps", 563, nntp_protocol_handler, 1, 1, 0, 1 },
|
{ "nntps", 563, nntp_protocol_handler, 1, 1, 0, 1, 0 },
|
||||||
{ "proxy", 3128, proxy_protocol_handler, 1, 1, 0, 0 },
|
{ "proxy", 3128, proxy_protocol_handler, 1, 1, 0, 0, 1 },
|
||||||
{ "smb", 139, smb_protocol_handler, 1, 1, 0, 0 },
|
{ "smb", 139, smb_protocol_handler, 1, 1, 0, 0, 1 },
|
||||||
{ "snews", 0, news_protocol_handler, 0, 0, 1, 0 },
|
{ "snews", 0, news_protocol_handler, 0, 0, 1, 0, 1 },
|
||||||
|
|
||||||
/* Keep these last! */
|
/* Keep these last! */
|
||||||
{ NULL, 0, NULL, 0, 0, 1, 0 },
|
{ NULL, 0, NULL, 0, 0, 1, 0, 1 },
|
||||||
|
|
||||||
{ "user", 0, NULL, 0, 0, 0, 0 },
|
{ "user", 0, NULL, 0, 0, 0, 0, 1 },
|
||||||
/* Internal protocol for mapping to protocol.user.* handlers. Placed
|
/* Internal protocol for mapping to protocol.user.* handlers. Placed
|
||||||
* last because it's checked first and else should be ignored. */
|
* last because it's checked first and else should be ignored. */
|
||||||
{ "custom", 0, NULL, 0, 0, 1, 0 },
|
{ "custom", 0, NULL, 0, 0, 1, 0, 1 },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -174,6 +175,14 @@ get_protocol_need_slash_after_host(enum protocol protocol)
|
|||||||
return protocol_backends[protocol].need_slash_after_host;
|
return protocol_backends[protocol].need_slash_after_host;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
get_protocol_keep_double_slashes(enum protocol protocol)
|
||||||
|
{
|
||||||
|
assert(VALID_PROTOCOL(protocol));
|
||||||
|
if_assert_failed return 0;
|
||||||
|
return protocol_backends[protocol].keep_double_slashes;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
get_protocol_free_syntax(enum protocol protocol)
|
get_protocol_free_syntax(enum protocol protocol)
|
||||||
{
|
{
|
||||||
|
@ -44,6 +44,7 @@ typedef void (protocol_external_handler_T)(struct session *, struct uri *);
|
|||||||
|
|
||||||
int get_protocol_port(enum protocol protocol);
|
int get_protocol_port(enum protocol protocol);
|
||||||
int get_protocol_need_slashes(enum protocol protocol);
|
int get_protocol_need_slashes(enum protocol protocol);
|
||||||
|
int get_protocol_keep_double_slashes(enum protocol protocol);
|
||||||
int get_protocol_need_slash_after_host(enum protocol protocol);
|
int get_protocol_need_slash_after_host(enum protocol protocol);
|
||||||
int get_protocol_free_syntax(enum protocol protocol);
|
int get_protocol_free_syntax(enum protocol protocol);
|
||||||
int get_protocol_need_ssl(enum protocol protocol);
|
int get_protocol_need_ssl(enum protocol protocol);
|
||||||
|
@ -673,7 +673,7 @@ normalize_uri(struct uri *uri, unsigned char *uristring)
|
|||||||
{
|
{
|
||||||
unsigned char *parse_string = uristring;
|
unsigned char *parse_string = uristring;
|
||||||
unsigned char *src, *dest, *path;
|
unsigned char *src, *dest, *path;
|
||||||
int need_slash = 0;
|
int need_slash = 0, keep_dslash = 1;
|
||||||
int parse = (uri == NULL);
|
int parse = (uri == NULL);
|
||||||
struct uri uri_struct;
|
struct uri uri_struct;
|
||||||
|
|
||||||
@ -701,8 +701,10 @@ normalize_uri(struct uri *uri, unsigned char *uristring)
|
|||||||
if (get_protocol_free_syntax(uri->protocol))
|
if (get_protocol_free_syntax(uri->protocol))
|
||||||
return uristring;
|
return uristring;
|
||||||
|
|
||||||
if (uri->protocol != PROTOCOL_UNKNOWN)
|
if (uri->protocol != PROTOCOL_UNKNOWN) {
|
||||||
need_slash = get_protocol_need_slash_after_host(uri->protocol);
|
need_slash = get_protocol_need_slash_after_host(uri->protocol);
|
||||||
|
keep_dslash = get_protocol_keep_double_slashes(uri->protocol);
|
||||||
|
}
|
||||||
|
|
||||||
path = uri->data - need_slash;
|
path = uri->data - need_slash;
|
||||||
dest = src = path;
|
dest = src = path;
|
||||||
@ -766,8 +768,7 @@ normalize_uri(struct uri *uri, unsigned char *uristring)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (is_uri_dir_sep(uri, src[1]) &&
|
} else if (is_uri_dir_sep(uri, src[1]) && !keep_dslash) {
|
||||||
uri->protocol == PROTOCOL_FILE) {
|
|
||||||
/* // - ignore first '/'. */
|
/* // - ignore first '/'. */
|
||||||
src += 1;
|
src += 1;
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user