Changeset fed4f76 for lib/misc.c


Ignore:
Timestamp:
2015-01-16T19:50:25Z (5 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
ecbd22a
Parents:
4cff28f
Message:

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)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/misc.c

    r4cff28f rfed4f76  
    780780        return NULL;
    781781}
     782
     783/* Takes a string, truncates it where it's safe, returns the new length */
     784int truncate_utf8( char *string, int maxlen )
     785{
     786        char *end;
     787        g_utf8_validate( (const gchar *) string, maxlen, (const gchar **) &end );
     788        *end = '\0';
     789        return end - string;
     790}
Note: See TracChangeset for help on using the changeset viewer.