mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
init_directory_listing: Link to original URLs. Decode for display only.
HTML-escape all strings that are not intended to contain markup.
This commit is contained in:
parent
b48a2d660d
commit
3ee04479d4
@ -47,12 +47,14 @@ enum connection_state
|
||||
init_directory_listing(struct string *page, struct uri *uri)
|
||||
{
|
||||
struct string dirpath = NULL_STRING;
|
||||
struct string decoded = NULL_STRING;
|
||||
struct string location = NULL_STRING;
|
||||
unsigned char *info;
|
||||
int local = (uri->protocol == PROTOCOL_FILE);
|
||||
|
||||
if (!init_string(page)
|
||||
|| !init_string(&dirpath)
|
||||
|| !init_string(&decoded)
|
||||
|| !init_string(&location)
|
||||
|| !add_uri_to_string(&dirpath, uri, URI_DATA)
|
||||
|| !add_uri_to_string(&location, uri, URI_DIR_LOCATION))
|
||||
@ -63,8 +65,12 @@ init_directory_listing(struct string *page, struct uri *uri)
|
||||
&& !add_char_to_string(&dirpath, local ? CHAR_DIR_SEP : '/'))
|
||||
goto out_of_memory;
|
||||
|
||||
/* Decode uri for displaying. */
|
||||
decode_uri_string(&dirpath);
|
||||
/* Decode uri for displaying. Do not use
|
||||
* add_string_to_string, because it for some reason returns
|
||||
* NULL if the second string is empty. */
|
||||
if (!add_bytes_to_string(&decoded, dirpath.source, dirpath.length))
|
||||
goto out_of_memory;
|
||||
decode_uri_string(&decoded);
|
||||
|
||||
if (!local && !add_char_to_string(&location, '/'))
|
||||
goto out_of_memory;
|
||||
@ -72,23 +78,15 @@ init_directory_listing(struct string *page, struct uri *uri)
|
||||
if (!add_to_string(page, "<html>\n<head><title>"))
|
||||
goto out_of_memory;
|
||||
|
||||
if (!local && !add_string_to_string(page, &location))
|
||||
if (!local && !add_html_to_string(page, location.source, location.length))
|
||||
goto out_of_memory;
|
||||
|
||||
if (!add_html_to_string(page, dirpath.source, dirpath.length)
|
||||
if (!add_html_to_string(page, decoded.source, decoded.length)
|
||||
|| !add_to_string(page, "</title>\n<base href=\"")
|
||||
|| !add_string_to_string(page, &location))
|
||||
|| !add_html_to_string(page, location.source, location.length)
|
||||
|| !add_html_to_string(page, dirpath.source, dirpath.length))
|
||||
goto out_of_memory;
|
||||
|
||||
#ifdef CONFIG_OS_WIN32
|
||||
/* Stupid. ':' and '\\' are encoded and base href with them
|
||||
* doesn't "work". */
|
||||
if (local)
|
||||
encode_win32_uri_string(page, dirpath.source, dirpath.length);
|
||||
else
|
||||
#endif
|
||||
encode_uri_string(page, dirpath.source, dirpath.length, 0);
|
||||
|
||||
if (!add_to_string(page, "\" />\n</head>\n<body>\n<h2>"))
|
||||
goto out_of_memory;
|
||||
|
||||
@ -122,20 +120,24 @@ init_directory_listing(struct string *page, struct uri *uri)
|
||||
|
||||
/* Make the directory path with links to each subdir. */
|
||||
{
|
||||
unsigned char *slash = dirpath.source;
|
||||
unsigned char *pslash = slash;
|
||||
unsigned char sep = local ? CHAR_DIR_SEP : '/';
|
||||
const unsigned char *slash = dirpath.source;
|
||||
const unsigned char *pslash = slash;
|
||||
const unsigned char sep = local ? CHAR_DIR_SEP : '/';
|
||||
|
||||
while ((slash = strchr(slash, sep)) != NULL) {
|
||||
done_string(&decoded);
|
||||
if (!init_string(&decoded)
|
||||
|| !add_bytes_to_string(&decoded, pslash, slash - pslash))
|
||||
goto out_of_memory;
|
||||
decode_uri_string(&decoded);
|
||||
|
||||
while ((slash = strchr(slash, sep))) {
|
||||
/* FIXME: htmlesc? At least we should escape quotes. --pasky */
|
||||
if (!add_to_string(page, "<a href=\"")
|
||||
|| !add_string_to_string(page, &location)
|
||||
|| !add_bytes_to_string(page, dirpath.source, slash - dirpath.source)
|
||||
|| !add_char_to_string(page, sep)
|
||||
|| !add_html_to_string(page, location.source, location.length)
|
||||
|| !add_html_to_string(page, dirpath.source, slash + 1 - dirpath.source)
|
||||
|| !add_to_string(page, "\">")
|
||||
|| !add_html_to_string(page, pslash, slash - pslash)
|
||||
|| !add_html_to_string(page, decoded.source, decoded.length)
|
||||
|| !add_to_string(page, "</a>")
|
||||
|| !add_char_to_string(page, sep))
|
||||
|| !add_html_to_string(page, &sep, 1))
|
||||
goto out_of_memory;
|
||||
|
||||
pslash = ++slash;
|
||||
@ -148,6 +150,7 @@ out_of_memory:
|
||||
}
|
||||
|
||||
done_string(&dirpath);
|
||||
done_string(&decoded);
|
||||
done_string(&location);
|
||||
|
||||
return page->length > 0 ? S_OK : S_OUT_OF_MEM;
|
||||
|
Loading…
Reference in New Issue
Block a user