mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-09 23:22:48 -04:00
Improve HTML parsing in libresapi
- Completely ignore content of <style> tags, otherwise CSS declarations from newer RS builds are displayed - Only remove <…> tags if it's really html, to prevent destroying messages from other webui users
This commit is contained in:
parent
b8c3c89ae0
commit
7aad9c12d0
1 changed files with 16 additions and 2 deletions
|
@ -337,10 +337,20 @@ void ChatHandler::tick()
|
||||||
|
|
||||||
void ChatHandler::getPlainText(const std::string& in, std::string &out, std::vector<Triple> &links)
|
void ChatHandler::getPlainText(const std::string& in, std::string &out, std::vector<Triple> &links)
|
||||||
{
|
{
|
||||||
|
if (in.size() == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (in[0] != '<' || in[in.size() - 1] != '>')
|
||||||
|
{
|
||||||
|
// It's a plain text message without HTML
|
||||||
|
out = in;
|
||||||
|
return;
|
||||||
|
}
|
||||||
bool ignore = false;
|
bool ignore = false;
|
||||||
|
|
||||||
bool keep_link = false;
|
bool keep_link = false;
|
||||||
std::string last_six_chars;
|
std::string last_six_chars;
|
||||||
|
unsigned int tag_start_index = 0;
|
||||||
Triple current_link;
|
Triple current_link;
|
||||||
for(unsigned int i = 0; i < in.size(); ++i)
|
for(unsigned int i = 0; i < in.size(); ++i)
|
||||||
{
|
{
|
||||||
|
@ -358,13 +368,17 @@ void ChatHandler::getPlainText(const std::string& in, std::string &out, std::vec
|
||||||
// "rising edge" sets mode to ignore
|
// "rising edge" sets mode to ignore
|
||||||
if(in[i] == '<')
|
if(in[i] == '<')
|
||||||
{
|
{
|
||||||
|
tag_start_index = i;
|
||||||
ignore = true;
|
ignore = true;
|
||||||
}
|
}
|
||||||
if(!ignore || keep_link)
|
if(!ignore || keep_link)
|
||||||
out += in[i];
|
out += in[i];
|
||||||
// "falling edge" resets mode to keep
|
// "falling edge" resets mode to keep
|
||||||
if(in[i] == '>')
|
if(in[i] == '>') {
|
||||||
ignore = false;
|
// leave ignore mode on, if it's a style tag
|
||||||
|
if (tag_start_index == 0 || tag_start_index + 6 > i || in.substr(tag_start_index, 6) != "<style")
|
||||||
|
ignore = false;
|
||||||
|
}
|
||||||
|
|
||||||
last_six_chars += in[i];
|
last_six_chars += in[i];
|
||||||
if(last_six_chars.size() > 6)
|
if(last_six_chars.size() > 6)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue