Browse Source

fixed encoding of UTF8 data (Jani Taskinen <sniper@iki.fi>)

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@942 152afb58-edef-0310-8abb-c4023f1b3aa9
svn/tags/lighttpd-1.4.11
Jan Kneschke 17 years ago
parent
commit
a1e6331f04
  1. 27
      src/buffer.c
  2. 12
      src/mod_dirlisting.c

27
src/buffer.c

@ -685,6 +685,28 @@ const char encoded_chars_html[] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* F0 - FF */
};
const char encoded_chars_minimal_xml[] = {
/*
0 1 2 3 4 5 6 7 8 9 A B C D E F
*/
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 00 - 0F control chars */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 10 - 1F */
0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 20 - 2F & */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, /* 30 - 3F < > */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 40 - 4F */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 50 - 5F */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 60 - 6F */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, /* 70 - 7F DEL */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 80 - 8F */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 90 - 9F */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* A0 - AF */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* B0 - BF */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* C0 - CF */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* D0 - DF */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* E0 - EF */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* F0 - FF */
};
const char encoded_chars_hex[] = {
/*
0 1 2 3 4 5 6 7 8 9 A B C D E F
@ -731,6 +753,9 @@ int buffer_append_string_encoded(buffer *b, const char *s, size_t s_len, buffer_
case ENCODING_HTML:
map = encoded_chars_html;
break;
case ENCODING_MINIMAL_XML:
map = encoded_chars_minimal_xml;
break;
case ENCODING_HEX:
map = encoded_chars_hex;
break;
@ -749,6 +774,7 @@ int buffer_append_string_encoded(buffer *b, const char *s, size_t s_len, buffer_
d_len += 3;
break;
case ENCODING_HTML:
case ENCODING_MINIMAL_XML:
d_len += 6;
break;
case ENCODING_HEX:
@ -774,6 +800,7 @@ int buffer_append_string_encoded(buffer *b, const char *s, size_t s_len, buffer_
d[d_len++] = hex_chars[(*ds) & 0x0F];
break;
case ENCODING_HTML:
case ENCODING_MINIMAL_XML:
d[d_len++] = '&';
d[d_len++] = '#';
d[d_len++] = 'x';

12
src/mod_dirlisting.c

@ -439,7 +439,7 @@ static void http_list_directory_header(server *srv, connection *con, plugin_data
"<head>\n"
"<title>Index of "
);
buffer_append_string_encoded(out, CONST_BUF_LEN(con->uri.path), ENCODING_HTML);
buffer_append_string_encoded(out, CONST_BUF_LEN(con->uri.path), ENCODING_MINIMAL_XML);
BUFFER_APPEND_STRING_CONST(out, "</title>\n");
if (p->conf.external_css->used > 1) {
@ -499,14 +499,14 @@ static void http_list_directory_header(server *srv, connection *con, plugin_data
if (-1 != stream_open(&s, p->tmp_buf)) {
BUFFER_APPEND_STRING_CONST(out, "<pre class=\"header\">");
buffer_append_string_encoded(out, s.start, s.size, ENCODING_HTML);
buffer_append_string_encoded(out, s.start, s.size, ENCODING_MINIMAL_XML);
BUFFER_APPEND_STRING_CONST(out, "</pre>");
}
stream_close(&s);
}
BUFFER_APPEND_STRING_CONST(out, "<h2>Index of ");
buffer_append_string_encoded(out, CONST_BUF_LEN(con->uri.path), ENCODING_HTML);
buffer_append_string_encoded(out, CONST_BUF_LEN(con->uri.path), ENCODING_MINIMAL_XML);
BUFFER_APPEND_STRING_CONST(out,
"</h2>\n"
"<div class=\"list\">\n"
@ -548,7 +548,7 @@ static void http_list_directory_footer(server *srv, connection *con, plugin_data
if (-1 != stream_open(&s, p->tmp_buf)) {
BUFFER_APPEND_STRING_CONST(out, "<pre class=\"readme\">");
buffer_append_string_encoded(out, s.start, s.size, ENCODING_HTML);
buffer_append_string_encoded(out, s.start, s.size, ENCODING_MINIMAL_XML);
BUFFER_APPEND_STRING_CONST(out, "</pre>");
}
stream_close(&s);
@ -744,7 +744,7 @@ static int http_list_directory(server *srv, connection *con, plugin_data *p, buf
BUFFER_APPEND_STRING_CONST(out, "<tr><td class=\"n\"><a href=\"");
buffer_append_string_encoded(out, DIRLIST_ENT_NAME(tmp), tmp->namelen, ENCODING_REL_URI_PART);
BUFFER_APPEND_STRING_CONST(out, "/\">");
buffer_append_string_encoded(out, DIRLIST_ENT_NAME(tmp), tmp->namelen, ENCODING_HTML);
buffer_append_string_encoded(out, DIRLIST_ENT_NAME(tmp), tmp->namelen, ENCODING_MINIMAL_XML);
BUFFER_APPEND_STRING_CONST(out, "</a>/</td><td class=\"m\">");
buffer_append_string_len(out, datebuf, sizeof(datebuf) - 1);
BUFFER_APPEND_STRING_CONST(out, "</td><td class=\"s\">- &nbsp;</td><td class=\"t\">Directory</td></tr>\n");
@ -800,7 +800,7 @@ static int http_list_directory(server *srv, connection *con, plugin_data *p, buf
BUFFER_APPEND_STRING_CONST(out, "<tr><td class=\"n\"><a href=\"");
buffer_append_string_encoded(out, DIRLIST_ENT_NAME(tmp), tmp->namelen, ENCODING_REL_URI_PART);
BUFFER_APPEND_STRING_CONST(out, "\">");
buffer_append_string_encoded(out, DIRLIST_ENT_NAME(tmp), tmp->namelen, ENCODING_HTML);
buffer_append_string_encoded(out, DIRLIST_ENT_NAME(tmp), tmp->namelen, ENCODING_MINIMAL_XML);
BUFFER_APPEND_STRING_CONST(out, "</a></td><td class=\"m\">");
buffer_append_string_len(out, datebuf, sizeof(datebuf) - 1);
BUFFER_APPEND_STRING_CONST(out, "</td><td class=\"s\">");

Loading…
Cancel
Save