1
0

Merge branch 'htmlescape'.

This commit is contained in:
madmaxoft 2013-10-20 09:14:30 +02:00
commit 0258213d24
4 changed files with 150 additions and 113 deletions

View File

@ -1785,7 +1785,10 @@ Sign entities are saved and loaded from disk when the chunk they reside in is sa
cWebAdmin =
{
Desc = "",
Functions = {},
Functions =
{
GetHTMLEscapedString = { Params = "string", Return = "string", Notes = "Gets the HTML escaped representation of a requested string. This is useful for user input and game data that is not guaranteed to be escaped already." },
},
Constants = {},
},

View File

@ -397,7 +397,38 @@ AString cWebAdmin::GetBaseURL( const AString& a_URL )
AString cWebAdmin::GetBaseURL( const AStringVector& a_URLSplit )
AString cWebAdmin::GetHTMLEscapedString(const AString & a_Input)
{
AString dst;
dst.reserve(a_Input.length());
// Loop over input and substitute HTML characters for their alternatives:
size_t len = a_Input.length();
for (size_t i = 0; i < len; i++)
{
switch (a_Input[i])
{
case '&': dst.append("&amp;"); break;
case '\'': dst.append("&apos;"); break;
case '"': dst.append("&quot;"); break;
case '<': dst.append("&lt;"); break;
case '>': dst.append("&gt;"); break;
default:
{
dst.push_back(a_Input[i]);
break;
}
} // switch (a_Input[i])
} // for i - a_Input[]
return dst;
}
AString cWebAdmin::GetBaseURL(const AStringVector & a_URLSplit)
{
AString BaseURL = "./";
if (a_URLSplit.size() > 1)

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);