Changeset 0f47613


Ignore:
Timestamp:
2007-12-10T22:57:13Z (16 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
d52111a
Parents:
71dc854
Message:

Don't allow nicks that start with a number.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • nick.c

    r71dc854 r0f47613  
    154154   With one difference, we allow dashes. */
    155155
    156 static char *nick_lc_chars = "0123456789abcdefghijklmnopqrstuvwxyz{}^-_|";
    157 static char *nick_uc_chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ[]~-_\\";
    158 
    159 void nick_strip( char * nick )
     156static char *nick_lc_chars = "0123456789abcdefghijklmnopqrstuvwxyz{}^`-_|";
     157static char *nick_uc_chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ[]~`-_\\";
     158
     159void nick_strip( char *nick )
    160160{
    161161        int i, j;
     
    170170                }
    171171        }
     172        if( isdigit( nick[0] ) )
     173        {
     174                char *orig;
     175               
     176                orig = g_strdup( nick );
     177                g_snprintf( nick, MAX_NICK_LENGTH, "_%s", orig );
     178                g_free( orig );
     179                j ++;
     180        }
    172181        while( j <= MAX_NICK_LENGTH )
    173182                nick[j++] = '\0';
     
    178187        const char *s;
    179188       
    180         /* Empty/long nicks are not allowed */
    181         if( !*nick || strlen( nick ) > MAX_NICK_LENGTH )
     189        /* Empty/long nicks are not allowed, nor numbers at [0] */
     190        if( !*nick || isdigit( nick[0] ) || strlen( nick ) > MAX_NICK_LENGTH )
    182191                return( 0 );
    183192       
  • tests/check_nick.c

    r71dc854 r0f47613  
    1515                "thisisave:ryveryveryverylongnick",
    1616                "t::::est",
     17                "test123",
     18                "123test",
     19                "123",
    1720                NULL };
    1821        const char *expected[] = { "test", "test", "test",
     
    2023                "thisisaveryveryveryveryl",
    2124                "test",
     25                "test123",
     26                "_123test",
     27                "_123",
    2228                NULL };
    2329
     
    3541START_TEST(test_nick_ok_ok)
    3642{
    37         const char *nicks[] = { "foo", "bar", "bla[", "blie]",
    38                                     "BreEZaH", "\\od^~", NULL };
     43        const char *nicks[] = { "foo", "bar123", "bla[", "blie]", "BreEZaH",
     44                                "\\od^~", "_123", "_123test", NULL };
    3945        int i;
    4046
     
    4955{
    5056        const char *nicks[] = { "thisisaveryveryveryveryveryveryverylongnick",
    51                                     "\nillegalchar", "", "nick%", NULL };
     57                                    "\nillegalchar", "", "nick%", "123test", NULL };
    5258        int i;
    5359
Note: See TracChangeset for help on using the changeset viewer.