Conversation
|
You need to add parsing to catch open tags. With this change as-is, I can write: <font face="Comic Sans MS">and deliberately not include the closing Alternatively, you could choose the sane option and not remove the HTML filter, which is there for a reason. |
Crystalwarrior
left a comment
There was a problem hiding this comment.
PLEASE descriptive descriptions I beg
src/aotextarea.cpp
Outdated
| QString result = p_message.toHtmlEscaped() | ||
| .replace("\n", "<br>") | ||
| .replace(url_parser_regex, "<a href='\\1'>\\1</a>"); | ||
| QString result = p_message.replace("\n", "<br>").replace(url_parser_regex, "<a href='\\1'>\\1</a>"); |
There was a problem hiding this comment.
we need to close all open HTML tags to prevent the Comic Sans disaster
src/aotextarea.cpp
Outdated
| std::string AOTextArea::closetags(std::string html) | ||
| { | ||
| std::regex opened_regex(R"(<([a-z]+)(?: .*)?(?<![/|/ ])>)", | ||
| std::regex_constants::icase); | ||
| std::regex closed_regex(R"(</([a-z]+)>)", std::regex_constants::icase); | ||
|
|
||
| std::vector<std::string> openedtags; | ||
| std::vector<std::string> closedtags; | ||
| std::smatch match; | ||
|
|
||
| std::string::const_iterator search_start(html.cbegin()); | ||
| while (std::regex_search(search_start, html.cend(), match, opened_regex)) { | ||
| openedtags.push_back(match[1]); | ||
| search_start = match.suffix().first; | ||
| } | ||
|
|
||
| search_start = html.cbegin(); | ||
| while (std::regex_search(search_start, html.cend(), match, closed_regex)) { | ||
| closedtags.push_back(match[1]); | ||
| search_start = match.suffix().first; | ||
| } | ||
|
|
||
| size_t len_opened = openedtags.size(); | ||
|
|
||
| if (closedtags.size() == len_opened) { | ||
| return html; | ||
| } | ||
|
|
||
| std::reverse(openedtags.begin(), openedtags.end()); | ||
| for (size_t i = 0; i < len_opened; i++) { | ||
| auto it = std::find(closedtags.begin(), closedtags.end(), openedtags[i]); | ||
| if (it == closedtags.end()) { | ||
| html += "</" + openedtags[i] + ">"; | ||
| } | ||
| else { | ||
| closedtags.erase(it); | ||
| } | ||
| } | ||
| return html; | ||
| } |
There was a problem hiding this comment.
can you rewrite this to use the Qt functions rather than std:: ones? we must be breaking some kind of convention somewhere by doing it this way lol
src/aotextarea.cpp
Outdated
| QString result = p_message.toHtmlEscaped() | ||
| .replace("\n", "<br>") | ||
| .replace(url_parser_regex, "<a href='\\1'>\\1</a>"); | ||
| QString result = QString::fromStdString(this->closetags(p_message.replace("\n", "<br>").toStdString())); |
There was a problem hiding this comment.
funny conversion to std:: moment, doesn't Qt have its own version of regex?
https://doc.qt.io/qt-5/qregexp.html#details
include/aotextarea.h
Outdated
| void append_chatmessage(QString p_name, QString p_message, | ||
| QString p_name_colour, QString p_color = QString()); | ||
| void append_error(QString p_message); | ||
| std::string closetags(std::string html); |
There was a problem hiding this comment.
can we use QString instead of std::string?
Crystalwarrior
left a comment
There was a problem hiding this comment.
looks good, now time to test
| QString result = this->closetags(p_message); | ||
| result = result.replace("\n", "<br>").replace(url_parser_regex, "<a href='\\1'>\\1</a>"); |
There was a problem hiding this comment.
For url parse regex we'll need to not do that if it's already handled via html
| html = html + expected_closetag; | ||
| } | ||
| } | ||
| return html; |


Removing html filter, to allow users to use bold, italic, colors ecc... in ooc message