Bug 4013 - ioQuake SanitizeString
Status: RESOLVED FIXED
Alias: None
Product: ioquake3
Classification: Unclassified
Component: Misc
Version: GIT MASTER
Hardware: PC All
: P3 normal
Assignee: Zachary J. Slater
QA Contact: ioquake3 bugzilla mailing list
URL:
Depends on:
Blocks:
 
Reported: 2009-03-11 23:46 EDT by Victor Roemer
Modified: 2009-05-08 05:31:13 EDT
1 user (show)

See Also:


Attachments
Patch (1.06 KB, patch)
2009-05-06 08:25 EDT, Victor Roemer
Real patch (1.08 KB, patch)
2009-05-06 08:31 EDT, Victor Roemer

Description Victor Roemer 2009-03-11 23:46:44 EDT
I hope I'm putting this in the correct place, The front page of ioquake3.org ( if you look for it ) says to post bugs here.

Anyways, in 'code/game/g_cmds.c' we have a function

/*
==================
SanitizeString

Remove case and control characters
==================
*/
void SanitizeString( char *in, char *out ) {
    while ( *in ) {
        if ( *in == 32 ) {
            in += 2;        // skip color code
            continue;
        }
        if ( *in < 32 ) {
            in++;
            continue;
        }
        *out++ = tolower( *in++ );
    }

    *out = 0;
}


The problem is in the first if statement. decimal 32 is 'ESC' 
so it should really be:

/*
==================
SanitizeString

Remove case and control characters
==================
*/
void SanitizeString( char *in, char *out ) {
    while ( *in ) {
        if ( *in == 94 ) {  // '^'
            in += 2;        // skip color code
            continue;
        }
        if ( *in < 32 ) {
            in++;
            continue;
        }
        *out++ = tolower( *in++ );
    }

    *out = 0;
}


This will properly strip color codes. I can provide in a patch upon request.
Comment 1 Victor Roemer 2009-03-12 00:43:37 EDT
Woops, I made a typo, the original is actually

/*
==================
SanitizeString

Remove case and control characters
==================
*/
void SanitizeString( char *in, char *out ) {
    while ( *in ) {
        if ( *in == 27 ) {
            in += 2;        // skip color code
            continue;
        }
        if ( *in < 32 ) {
            in++;
            continue;
        }
        *out++ = tolower( *in++ );
    }

    *out = 0;
}


and '27' decimal is ESC.
Comment 2 Ludwig Nussel 2009-05-02 13:49:57 EDT
Nice catch. That function is only used by the 'follow' command. Shouldn't it use Q_CleanStr instead? Would you mind sending a patch that makes use of Q_CleanStr?
Comment 3 Victor Roemer 2009-05-06 08:25:42 EDT
Created attachment 2053 [details]
Patch

I think this is correct, all I did was made sure it compiled. One thing to note is that Q_CleanStr doesn't convert to lowercase where SanitizeString did.
Comment 4 Victor Roemer 2009-05-06 08:31:22 EDT
Created attachment 2054 [details]
Real patch

I oops on the last one, this one is correct...
Comment 5 Ludwig Nussel 2009-05-08 05:31:13 EDT
that one didn't make the behavior consistent with other command like kick either. I've applied a modified version. Note that this is game code anyways so unless you develop a mod yourself you won't benefit from the changes.