1
0

Added a HTML escaping function to cWebAdmin.

Apparently my editor fixed some failed tabs too.
This commit is contained in:
Alexander Harkness 2013-10-19 17:17:33 +01:00
parent be996c1662
commit 9701a7fb84
2 changed files with 80 additions and 38 deletions

View File

@ -397,6 +397,45 @@ AString cWebAdmin::GetBaseURL( const AString& a_URL )
AString cWebAdmin::GetHTMLEscapedString( const AString& a_Input )
{
// Define a stringstream to write the output to.
std::stringstream dst;
// Loop over input and substitute HTML characters for their alternatives.
for (char workingCharacter : a_Input) {
switch (workingCharacter)
{
case '&':
dst << "&amp;";
break;
case '\'':
dst << "&apos;";
break;
case '"':
dst << "&quot;";
break;
case '<':
dst << "&lt;";
break;
case '>':
dst << "&gt;";
break;
default:
dst << workingCharacter;
break;
}
}
return dst.str();
}
AString cWebAdmin::GetBaseURL( const AStringVector& a_URLSplit )
{
AString BaseURL = "./";

View File

@ -132,6 +132,9 @@ public:
AString GetBaseURL(const AString& a_URL);
// Escapes text passed into it, so it can be embedded into html.
AString GetHTMLEscapedString( const AString& a_Input );
// tolua_end
AString GetBaseURL(const AStringVector& a_URLSplit);