http link and nick length fix

master 2.0.1
const an teen 2021-12-13 02:22:25 -05:00
parent f8abf1604b
commit c187a5869f
1 changed files with 15 additions and 2 deletions

View File

@ -13,6 +13,8 @@
#include <QFile> #include <QFile>
#include <QDir> #include <QDir>
constexpr int MAX_MESSAGE_LENGTH_WITHOUT_WBR = 30;
constexpr int MAX_NICKNAME_LENGTH_WITHOUT_WBR = 20;
constexpr int BUFFER_SIZE = 2048; constexpr int BUFFER_SIZE = 2048;
HttpServer::HttpServer(const QString &address, quint16 port, const QString& logFolder, HttpServer::HttpServer(const QString &address, quint16 port, const QString& logFolder,
@ -46,7 +48,8 @@ QString HttpServer::convertToClickableLink(const QString &httpLine)
QString displayedName {httpLine}; QString displayedName {httpLine};
displayedName.remove(QRegularExpression("http.?://(www\\.)?")); displayedName.remove(QRegularExpression("http.?://(www\\.)?"));
result = "<a href=\"" + httpLine + "\"> " + displayedName + "</a>"; displayedName.remove(QRegularExpression("/$"));
result = "<a href=\"" + httpLine + "\"> " + displayedName + " </a>";
return result; return result;
} }
@ -67,6 +70,16 @@ std::pair<QString, QString> HttpServer::splitUserNameAndMessage(const QString &r
return result; return result;
} }
// long nicks
if (nick.size() > MAX_NICKNAME_LENGTH_WITHOUT_WBR) {
int lastWbr = 0;
for (int i = 0; i < nick.size(); i++) {
if (i-lastWbr > MAX_NICKNAME_LENGTH_WITHOUT_WBR) {
nick.insert(i, "<wbr>");
lastWbr = i;
}
}
}
// http links // http links
while (QRegularExpression("(^|\\s)http.?://").match(text).hasMatch()) { while (QRegularExpression("(^|\\s)http.?://").match(text).hasMatch()) {
int pos = text.indexOf(QRegularExpression("(^|\\s)http.?://")); int pos = text.indexOf(QRegularExpression("(^|\\s)http.?://"));
@ -100,7 +113,7 @@ std::pair<QString, QString> HttpServer::splitUserNameAndMessage(const QString &r
} }
} }
} }
if (not isHref and i-space > 30) { if (not isHref and i-space > MAX_MESSAGE_LENGTH_WITHOUT_WBR) {
text.insert(i, "<wbr>"); text.insert(i, "<wbr>");
space = i; space = i;
} }