Changeset fed4f76 for nick.c


Ignore:
Timestamp:
2015-01-16T19:50:25Z (9 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
  • nick.c

    r4cff28f rfed4f76  
    227227        {
    228228                nick_strip( irc, rets );
    229                 rets[MAX_NICK_LENGTH] = '\0';
     229                truncate_utf8( rets, MAX_NICK_LENGTH );
    230230                return rets;
    231231        }
     
    252252                else
    253253                {
    254                         nick[0] ++;
     254                        /* We've got no more space for underscores,
     255                           so truncate it and replace the last three
     256                           chars with a random "_XX" suffix */
     257                        int len = truncate_utf8( nick, MAX_NICK_LENGTH - 3 );
     258                        nick[len] = '_';
     259                        g_snprintf(nick + len + 1, 3, "%2x", rand() );
    255260                }
    256261               
     
    400405                if( strlen( down ) > strlen( nick ) )
    401406                {
    402                         /* Well crap. Corrupt it if we have to. */
    403                         down[strlen(nick)] = '\0';
     407                        truncate_utf8( down, strlen(nick) );
    404408                }
    405409                strcpy( nick, down );
Note: See TracChangeset for help on using the changeset viewer.