--- a/src/util.c Thu Mar 17 22:01:41 2005 -0500
+++ b/src/util.c Fri Mar 18 14:52:34 2005 -0500
@@ -2904,19 +2904,29 @@
gaim_url_encode(const char *str)
static char buf[BUF_LEN];
g_return_val_if_fail(str != NULL, NULL);
- for (i = 0; i < strlen(str) && j < (BUF_LEN - 1); i++) {
- sprintf(buf + j, "%%%02x", (unsigned char)str[i]);
+ g_return_val_if_fail(g_utf8_validate(str, -1, NULL), NULL); + for (; *iter && j < (BUF_LEN - 1) ; iter = g_utf8_next_char(iter)) { + gunichar c = g_utf8_get_char(iter); + /* If the character is an ASCII character and is alphanumeric, + * or one of the specified values, no need to escape */ + if (c < 256 && isalnum(c)) { + int bytes = g_unichar_to_utf8(c, utf_char); + for (i = 0; i < bytes; i++) { + sprintf(buf + j, "%%%02x", utf_char[i] & 0xff); @@ -3269,20 +3279,30 @@
gaim_escape_filename(const char *str)
static char buf[BUF_LEN];
g_return_val_if_fail(str != NULL, NULL);
- for (i = 0; i < strlen(str) && j < (BUF_LEN - 1); i++) {
- if (isalnum(str[i]) || str[i] == '@' || str[i] == '-' ||
- str[i] == '_' || str[i] == '.' || str[i] == '#')
- sprintf(buf + j, "%%%02x", (unsigned char)str[i]);
+ g_return_val_if_fail(g_utf8_validate(str, -1, NULL), NULL); + for (; *iter && j < (BUF_LEN - 1) ; iter = g_utf8_next_char(iter)) { + gunichar c = g_utf8_get_char(iter); + /* If the character is an ASCII character and is alphanumeric, + * or one of the specified values, no need to escape */ + if (c < 256 && (isalnum(c) || c == '@' || c == '-' || + c == '_' || c == '.' || c == '#')) { + int bytes = g_unichar_to_utf8(c, utf_char); + for (i = 0; i < bytes; i++) { + sprintf(buf + j, "%%%02x", utf_char[i] & 0xff);