diff options
author | dequis <dx@dxzone.com.ar> | 2015-01-16 16:50:25 -0300 |
---|---|---|
committer | dequis <dx@dxzone.com.ar> | 2015-01-16 16:50:25 -0300 |
commit | fed4f766c05e44e99917909b266c99c052ed9c3e (patch) | |
tree | ca0f96eba21d6fd019b40a6f2d2af8f0d0ebecb9 /lib/misc.c | |
parent | 4cff28fdfca2eaf71a13715b0fda114796091065 (diff) |
Fix UTF8 nick truncation issues
When nicks exceeded the length limit, they were cut at 24 bytes and that
sometimes left invalid utf8 at the end, which made the nick_ok()
validation fail and often broke those nicks completely.
This adds a truncate_utf8 function to cut the string at a safe place
Also, the method to deduplicate nicks when there's no more place to add
underscores was changed to add "_XX" at the end, where XX are two random
hex chars. The previous method in those cases was increasing the value
of the first character of the nick... which leads to silly and confusing
results (i.e. FacebookUser -> GacebookUser)
Diffstat (limited to 'lib/misc.c')
-rw-r--r-- | lib/misc.c | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -779,3 +779,12 @@ char *get_rfc822_header( const char *text, const char *header, int len ) return NULL; } + +/* Takes a string, truncates it where it's safe, returns the new length */ +int truncate_utf8( char *string, int maxlen ) +{ + char *end; + g_utf8_validate( (const gchar *) string, maxlen, (const gchar **) &end ); + *end = '\0'; + return end - string; +} |