Skip to content
Permalink
Browse files

HTML-escape names of keyboard keys where appropriate

  • Loading branch information...
slipher committed Mar 31, 2019
1 parent 12fa185 commit 2f3bddb802ece26803a20a4afb4cedd33d634ef3
@@ -3294,7 +3294,6 @@ static void CG_Rocket_DrawPlayerUnlockedItems()

static void CG_Rocket_DrawVote_internal( team_t team )
{
char *s;
int sec;

if ( !cgs.voteTime[ team ] )
@@ -3317,16 +3316,16 @@ static void CG_Rocket_DrawVote_internal( team_t team )
sec = 0;
}

Rocket::Core::String yeskey = CG_KeyBinding( va( "%svote yes", team == TEAM_NONE ? "" : "team" ), team );
Rocket::Core::String nokey = CG_KeyBinding( va( "%svote no", team == TEAM_NONE ? "" : "team" ), team );
std::string yeskey = CG_EscapeHTMLText( CG_KeyBinding( va( "%svote yes", team == TEAM_NONE ? "" : "team" ), team ) );
std::string nokey = CG_EscapeHTMLText( CG_KeyBinding( va( "%svote no", team == TEAM_NONE ? "" : "team" ), team ) );

s = va( "%sVOTE(%i): %s\n"
std::string s = Str::Format( "%sVOTE(%i): %s\n"
" Called by: \"%s\"\n"
" [%s][<span class='material-icon'>&#xe8dc;</span>]:%i [%s][<span class='material-icon'>&#xe8db;</span>]:%i\n",
team == TEAM_NONE ? "" : "TEAM", sec, cgs.voteString[ team ],
cgs.voteCaller[ team ], yeskey.CString(), cgs.voteYes[ team ], nokey.CString(), cgs.voteNo[ team ] );
cgs.voteCaller[ team ], yeskey, cgs.voteYes[ team ], nokey, cgs.voteNo[ team ] );

Rocket_SetInnerRML( s, 0 );
Rocket_SetInnerRML( s.c_str(), 0 );
}

static void CG_Rocket_DrawVote()
@@ -485,6 +485,28 @@ static bool IsInvalidEmoticon( Rocket::Core::String emoticon )
return false;
}

std::string CG_EscapeHTMLText( Str::StringRef text )
{
std::string out;
for (char c : text) {
switch (c) {
case '<':
out += "&lt;";
break;
case '>':
out += "&gt;";
break;
case '&':
out += "&amp;";
break;
default:
out += c;
break;
}
}
return out;
}

// TODO: Make this take Rocket::Core::String as an input.
Rocket::Core::String Rocket_QuakeToRML( const char *in, int parseFlags = 0 )
{
@@ -41,6 +41,7 @@ Maryland 20850 USA.

#include "common/Compiler.h"
#include "common/Color.h"
#include "common/String.h"

#ifdef __GNUC__
#pragma GCC diagnostic push
@@ -74,8 +75,12 @@ class RocketEvent_t
Rocket::Core::String cmd;
};

// HTML-escape a string that will be used as text. Text meaning that it will be not be
// somewhere weird like inside a tag, which may require a different form of escaping.
std::string CG_EscapeHTMLText( Str::StringRef text );

Rocket::Core::String Rocket_QuakeToRML( const char *in, int parseFlags );
Rocket::Core::String CG_KeyBinding( const char *bind, int team );
std::string CG_KeyBinding( const char *bind, int team );

void Rocket_AddEvent( RocketEvent_t *event );

@@ -98,7 +98,7 @@ class RocketKeyBinder : public Rocket::Core::Element, public Rocket::Core::Event
if ( rocketInfo.realtime >= nextKeyUpdateTime && team >= 0 && !cmd.Empty() && !waitingForKeypress )
{
nextKeyUpdateTime = rocketInfo.realtime + KEY_BINDING_REFRESH_INTERVAL_MS;
SetInnerRML( CG_KeyBinding( cmd.CString(), team ) );
SetInnerRML( CG_EscapeHTMLText( CG_KeyBinding( cmd.CString(), team ) ).c_str() );
}
}

@@ -313,7 +313,7 @@ void Rocket_MouseMove( int x, int y )
CG_KeyBinding
================
*/
Rocket::Core::String CG_KeyBinding( const char* bind, int team )
std::string CG_KeyBinding( const char* bind, int team )
{
std::vector<Keyboard::Key> keys = trap_Key_GetKeysForBinds( team, {bind} )[0];

@@ -322,7 +322,7 @@ Rocket::Core::String CG_KeyBinding( const char* bind, int team )
return "Unbound";
}

Rocket::Core::String keyNames = CG_KeyDisplayName( keys[0] ).c_str();
std::string keyNames = CG_KeyDisplayName( keys[0] );

for ( size_t i = 1; i < keys.size(); i++ )
{

0 comments on commit 2f3bddb

Please sign in to comment.
You can’t perform that action at this time.