commit
89cac562cf
|
@ -34,6 +34,7 @@ void ApiTest::your_method_name(const HttpRequestPtr &req, const std::function<vo
|
||||||
std::map<std::string, std::string> para;
|
std::map<std::string, std::string> para;
|
||||||
para["p1"] = std::to_string(p1);
|
para["p1"] = std::to_string(p1);
|
||||||
para["p2"] = std::to_string(p2);
|
para["p2"] = std::to_string(p2);
|
||||||
|
para["p3"] = HttpViewData::htmlTranslate("<script>alert(\" This should not be displayed in a browser alert box.\");</script>");
|
||||||
data.insert("parameters", para);
|
data.insert("parameters", para);
|
||||||
auto res = HttpResponse::newHttpViewResponse("ListParaView", data);
|
auto res = HttpResponse::newHttpViewResponse("ListParaView", data);
|
||||||
callback(res);
|
callback(res);
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
GIT_VER=$(git log|grep ^commit|wc -l|sed -e "s/^ *//")
|
GIT_VER=$(git log|grep ^commit|wc -l|sed -e "s/^ *//")
|
||||||
MD5=$(git log|head -1|awk '{printf $2}')
|
MD5=$(git log|head -1|awk '{printf $2}')
|
||||||
TMP_FILE=/tmp/version
|
TMP_FILE=/tmp/version
|
||||||
echo "#define VERSION \"0.9.25.$GIT_VER\"" > ${TMP_FILE}
|
echo "#define VERSION \"0.9.26.$GIT_VER\"" > ${TMP_FILE}
|
||||||
echo "#define VERSION_MD5 \"$MD5\"" >> ${TMP_FILE}
|
echo "#define VERSION_MD5 \"$MD5\"" >> ${TMP_FILE}
|
||||||
if [ ! -f $1 ];then
|
if [ ! -f $1 ];then
|
||||||
mv -f ${TMP_FILE} $1
|
mv -f ${TMP_FILE} $1
|
||||||
|
|
|
@ -119,6 +119,15 @@ class HttpViewData
|
||||||
return _viewData[key];
|
return _viewData[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Translate some special characters to HTML format, such as:
|
||||||
|
/**
|
||||||
|
* " --> "
|
||||||
|
* & --> &
|
||||||
|
* < --> <
|
||||||
|
* > --> >
|
||||||
|
*/
|
||||||
|
static std::string htmlTranslate(const std::string &str);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
typedef std::unordered_map<std::string, any> ViewDataMap;
|
typedef std::unordered_map<std::string, any> ViewDataMap;
|
||||||
mutable ViewDataMap _viewData;
|
mutable ViewDataMap _viewData;
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* HttpViewData.cc
|
||||||
|
* An Tao
|
||||||
|
*
|
||||||
|
* Copyright 2018, An Tao. All rights reserved.
|
||||||
|
* https://github.com/an-tao/drogon
|
||||||
|
* Use of this source code is governed by a MIT license
|
||||||
|
* that can be found in the License file.
|
||||||
|
*
|
||||||
|
* Drogon
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <drogon/HttpViewData.h>
|
||||||
|
|
||||||
|
using namespace drogon;
|
||||||
|
|
||||||
|
std::string HttpViewData::htmlTranslate(const std::string &str)
|
||||||
|
{
|
||||||
|
std::string ret;
|
||||||
|
ret.reserve(str.length());
|
||||||
|
for (auto &ch : str)
|
||||||
|
{
|
||||||
|
switch (ch)
|
||||||
|
{
|
||||||
|
case '"':
|
||||||
|
ret.append(""");
|
||||||
|
break;
|
||||||
|
case '<':
|
||||||
|
ret.append("<");
|
||||||
|
break;
|
||||||
|
case '>':
|
||||||
|
ret.append(">");
|
||||||
|
break;
|
||||||
|
case '&':
|
||||||
|
ret.append("&");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ret.push_back(ch);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
Loading…
Reference in New Issue