}
/**
- * @brief Check if tag is in a whitelist of alowed tags.
+ * @brief Check if tag is in a whitelist of allowed tags.
* Does not accept a tag containing attributes.
* Example:
* <h1> or </p> returns true.
string result = "";
vector<string> expected_tags;
- BOOST_FOREACH(TOKEN s, tokenized)
+ BOOST_FOREACH(const TOKEN &s, tokenized)
{
if (!s.second)
{
{
result = result + s.first;
if (to_lower(s.first).compare("<br>") != 0)
- expected_tags.push_back(s.first.insert(1,"/"));
+ expected_tags.push_back("</"+s.first.substr(1));
continue;
}
else if (expected_tags.size() > 0 && expected_tags.back().compare(s.first) == 0)
}
}
- if (to_lower(s.first).compare(0, AHREF.size(), AHREF) == 0 && link_sanitizer(s.first))
+ string tag = s.first;
+ if (to_lower(s.first).compare(0, AHREF.size(), AHREF) == 0 && link_sanitizer(tag))
{
- result = result + s.first;
+ result = result + tag;
expected_tags.push_back("</a>");
continue;
}
}
if (expected_tags.size() > 0) //One or more tags were not closed.
+ {
BOOST_REVERSE_FOREACH(const string &s, expected_tags)
{
result = result + s;
}
+ }
return result.c_str();
}
/**
* @brief Restricts html code to a small list of allowed tags.
* The attribute "href" from the tag "a" has its value sanitized and if it
- * contains unsafe caracters, the tag is stripped.
+ * contains unsafe characters, the tag is stripped.
* The link sanitizer adds a redirector in case of an acceptable protocol, strip otherwise.
* Any other attributes found will result in the tag being stripped.
* Any comments will be excluded.