|
@@ -1533,25 +1533,32 @@ getNumericNameInfo(const struct sockaddr* sockaddr, socklen_t len)
|
|
|
|
|
|
std::string htmlEscape(const std::string& src)
|
|
|
{
|
|
|
- std::string dest;
|
|
|
- for(std::string::const_iterator i = src.begin(), eoi = src.end();
|
|
|
- i != eoi; ++i) {
|
|
|
- char ch = *i;
|
|
|
- if(ch == '<') {
|
|
|
- dest += "<";
|
|
|
- } else if(ch == '>') {
|
|
|
- dest += ">";
|
|
|
- } else if(ch == '&') {
|
|
|
- dest += "&";
|
|
|
- } else if(ch == '\'') {
|
|
|
- dest += "'";
|
|
|
- } else if(ch == '"') {
|
|
|
- dest += """;
|
|
|
- } else {
|
|
|
- dest += ch;
|
|
|
+ std::string rv(src);
|
|
|
+ std::string::size_type pos = 0;
|
|
|
+ while ((pos = rv.find_first_of("<>&\"'", pos)) != std::string::npos) {
|
|
|
+ auto ch = rv[pos];
|
|
|
+ if (ch == '<') {
|
|
|
+ rv.replace(pos, 1, "<");
|
|
|
+ pos += 4;
|
|
|
+ }
|
|
|
+ else if (ch == '>') {
|
|
|
+ rv.replace(pos, 1, ">");
|
|
|
+ pos += 4;
|
|
|
+ }
|
|
|
+ else if (ch == '&') {
|
|
|
+ rv.replace(pos, 1, "&");
|
|
|
+ pos += 5;
|
|
|
+ }
|
|
|
+ else if (ch == '"') {
|
|
|
+ rv.replace(pos, 1, """);
|
|
|
+ pos += 6;
|
|
|
+ }
|
|
|
+ else { // '\''
|
|
|
+ rv.replace(pos, 1, "'");
|
|
|
+ pos += 5;
|
|
|
}
|
|
|
}
|
|
|
- return dest;
|
|
|
+ return rv;
|
|
|
}
|
|
|
|
|
|
std::pair<size_t, std::string>
|