final html tags fixes

master
const an teen 2021-12-15 09:51:53 -05:00
parent 6f520c4575
commit 76e1d6a1de
2 changed files with 21 additions and 7 deletions

View File

@ -70,10 +70,10 @@ std::pair<QString, QString> HttpServer::splitUserNameAndMessage(const QString &r
return result;
}
text.replace('&', "&amp;");
text.replace('<', "&lt;");
text.replace('>', "&gt;");
text.replace('\"', "&quot;");
nick.replace('&', "&amp;");
nick.replace('<', "&lt;");
nick.replace('>', "&gt;");
nick.replace('\"', "&quot;");
// long nicks
if (nick.size() > MAX_NICKNAME_LENGTH_WITHOUT_WBR) {
@ -86,6 +86,11 @@ std::pair<QString, QString> HttpServer::splitUserNameAndMessage(const QString &r
}
}
text.replace('&', "&amp;");
text.replace('<', "&lt;");
text.replace('>', "&gt;");
text.replace('\"', "&quot;");
// http links
while (QRegularExpression("(^|\\s)http.?://").match(text).hasMatch()) {
int pos = text.indexOf(QRegularExpression("(^|\\s)http.?://"));
@ -106,6 +111,7 @@ std::pair<QString, QString> HttpServer::splitUserNameAndMessage(const QString &r
}
// long lines
int space = 0;
bool nbTag = false; // For safe HTML tags like a &it; via <wbr>!
bool isHref = false;
for (int i = 0; i < text.size(); i++) {
if (text[i] == ' ') {
@ -119,7 +125,15 @@ std::pair<QString, QString> HttpServer::splitUserNameAndMessage(const QString &r
}
}
}
if (not isHref and i-space > MAX_MESSAGE_LENGTH_WITHOUT_WBR) {
if (nbTag and text[i] == ';') {
nbTag = false;
}
if (text.indexOf(QRegularExpression("(\\&amp;|\\&lt;|\\&gt;|\\&quot;).*"), i) == i) {
nbTag = true;
}
if (not isHref and i-space > MAX_MESSAGE_LENGTH_WITHOUT_WBR and not nbTag) {
text.insert(i, "<wbr>");
space = i;
}
@ -818,7 +832,7 @@ void HttpServer::writeMainPage(QTcpSocket *socket, QString &urlPath, bool isHead
for(const auto& m: messages) {
payloadBlock += m;
}
payloadBlock += "&nbsp";
payloadBlock += "&nbsp;\n";
}
}
}

View File

@ -56,7 +56,7 @@ int main(int argc, char *argv[])
" | $$ | $$ \\ $$| $$ $$ /$$__ $$| $$ \\ $$| $$ | $$ | $$ /$$\n"
" /$$$$$$| $$ | $$| $$$$$$/| $$$$$$$| $$$$$$$/| $$$$$$/ | $$$$/\n"
"|______/|__/ |__/ \\______/ \\_______/|_______/ \\______/ \\___/";
qInfo().noquote() << "IRCaBot" << IRCABOT_VERSION << " | Source code: https://notabug.org/acetone/ircabot";
qInfo().noquote() << "IRCaBot" << IRCABOT_VERSION << "| Source code: https://notabug.org/acetone/ircabot";
qInfo().noquote() << "GPLv3 (c) acetone," << COPYRIGHT_YEAR << "\n";
ApplicationData configuration(configFile);