Following the bug report at [1] and a short discussion on IRC, this changes webadmin HTML pages' default charset to UTF-8. Since we do not have a routine that detects an input's charset or even converts it to UTF-8, this will cause ISO-8859-1(1) or other non UTF-8 encoded inputs that have been set e.g. as module arguments from IRC or from a non-UTF-8 shell console to show up garbled in webadmin. A possible fix would be to convert strings to UTF-8 before inserting them into the templates. We'll see what the future holds.

[1] http://sourceforge.net/tracker/index.php?func=detail&aid=2933280&group_id=115828&atid=672821


git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1716 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
cflakes
2010-01-18 19:52:16 +00:00
parent 202029d51f
commit 911e778357
5 changed files with 16 additions and 127 deletions
+12 -123
View File
@@ -15,121 +15,6 @@
using std::stringstream;
static const char* const g_szHTMLescapes[256] = {
"�", 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0-9
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 10-19
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 20-29
0, 0, 0, 0, """, 0, 0, 0, "&", "'", // 30-39
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 40-49
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 50-59
"<", 0, ">", 0, 0, 0, 0, 0, 0, 0, // 60-69
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 70-79
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 80-89
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 90-99
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 100-109
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 110-119
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 120-129
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 130-139
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 140-149
0, 0, 0, "™", 0, 0, 0, 0, 0, 0, // 150-159
" ", // 160
"¡", // 161
"¢", // 162
"£", // 163
"¤", // 164
"¥", // 165
"¦", // 166
"§", // 167
"¨", // 168
"©", // 169
"ª", // 170
"«", // 171
"¬", // 172
"­", // 173
"®", // 174
"¯", // 175
"°", // 176
"±", // 177
"²", // 178
"³", // 179
"´", // 180
"µ", // 181
"¶", // 182
"·", // 183
"¸", // 184
"¹", // 185
"º", // 186
"»", // 187
"¼", // 188
"½", // 189
"¾", // 190
"¿", // 191
"À", // 192
"Á", // 193
"Â", // 194
"Ã", // 195
"Ä", // 196
"Å", // 197
"Æ", // 198
"Ç", // 199
"È", // 200
"É", // 201
"Ê", // 202
"Ë", // 203
"Ì", // 204
"Í", // 205
"Î", // 206
"Ï", // 207
"Ð", // 208
"Ñ", // 209
"Ò", // 210
"Ó", // 211
"Ô", // 212
"Õ", // 213
"Ö", // 214
"×", // 215
"Ø", // 216
"Ù", // 217
"Ú", // 218
"Û", // 219
"Ü", // 220
"Ý", // 221
"Þ", // 222
"ß", // 223
"à", // 224
"á", // 225
"â", // 226
"ã", // 227
"ä", // 228
"å", // 229
"æ", // 230
"ç", // 231
"è", // 232
"é", // 233
"ê", // 234
"ë", // 235
"ì", // 236
"í", // 237
"î", // 238
"ï", // 239
"ð", // 240
"ñ", // 241
"ò", // 242
"ó", // 243
"ô", // 244
"õ", // 245
"ö", // 246
"÷", // 247
"ø", // 248
"ù", // 249
"ú", // 250
"û", // 251
"ü", // 252
"ý", // 253
"þ", // 254
"ÿ", // 255
};
CString::CString(char c) : string() { stringstream s; s << c; *this = s.str(); }
CString::CString(unsigned char c) : string() { stringstream s; s << c; *this = s.str(); }
CString::CString(short i) : string() { stringstream s; s << i; *this = s.str(); }
@@ -307,6 +192,8 @@ CString CString::Escape_n(EEscape eFrom, EEscape eTo) const {
switch (eFrom) {
case EHTML:
if ((*p == '&') && (strnchr((unsigned char*) p, ';', sizeof(pTmp) - 1, pTmp, &iCounted))) {
// please note that we do not have any Unicode or UTF-8 support here at all.
if ((iCounted >= 3) && (pTmp[1] == '#')) { // do XML and HTML &#97; &#x3c
int base = 10;
@@ -324,11 +211,11 @@ CString CString::Escape_n(EEscape eFrom, EEscape eTo) const {
}
}
for (unsigned int c = 0; c < 256; c++) {
if (g_szHTMLescapes[c] && strcmp(g_szHTMLescapes[c], (const char*) &pTmp) == 0) {
ch = c;
break;
}
if (ch == 0) {
if (!strncasecmp((const char*) &pTmp, "lt", 2)) ch = '<';
else if (!strncasecmp((const char*) &pTmp, "gt", 2)) ch = '>';
else if (!strncasecmp((const char*) &pTmp, "quot", 4)) ch = '"';
else if (!strncasecmp((const char*) &pTmp, "amp", 3)) ch = '&';
}
if (ch > 0) {
@@ -394,9 +281,11 @@ CString CString::Escape_n(EEscape eFrom, EEscape eTo) const {
switch (eTo) {
case EHTML:
if (g_szHTMLescapes[ch]) {
sRet += g_szHTMLescapes[ch];
} else {
if (ch == '<') sRet += "&lt;";
else if (ch == '>') sRet += "&gt;";
else if (ch == '"') sRet += "&quot;";
else if (ch == '&') sRet += "&amp;";
else {
sRet += ch;
}
@@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>ZNC - Webadmin module - <?VAR Title ESC=HTML?></title>
<link rel="stylesheet" type="text/css" href="<?VAR Skin ESC=URL?>/main.css">
</head>
+1 -1
View File
@@ -1,8 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>ZNC - <?VAR Title ESC=HTML?></title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="<?VAR Skin ESC=URL?>/main.css" />
</head>
+1 -1
View File
@@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>ZNC - Webadmin module - <?VAR Title ESC=HTML?></title>
<link rel="stylesheet" type="text/css" href="<?VAR Skin ESC=URL?>/main.css">
</head>
+1 -1
View File
@@ -1,8 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>ZNC - <?VAR Title ESC=HTML?></title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="<?VAR Skin ESC=URL?>/main.css" />
</head>