From c187a5869f84be001144f8cad4ee7733c4f5369d Mon Sep 17 00:00:00 2001 From: acetone Date: Mon, 13 Dec 2021 02:22:25 -0500 Subject: [PATCH] http link and nick length fix --- httpserver.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/httpserver.cpp b/httpserver.cpp index 096dc98..4e8b7f5 100644 --- a/httpserver.cpp +++ b/httpserver.cpp @@ -13,6 +13,8 @@ #include #include +constexpr int MAX_MESSAGE_LENGTH_WITHOUT_WBR = 30; +constexpr int MAX_NICKNAME_LENGTH_WITHOUT_WBR = 20; constexpr int BUFFER_SIZE = 2048; HttpServer::HttpServer(const QString &address, quint16 port, const QString& logFolder, @@ -46,7 +48,8 @@ QString HttpServer::convertToClickableLink(const QString &httpLine) QString displayedName {httpLine}; displayedName.remove(QRegularExpression("http.?://(www\\.)?")); - result = " " + displayedName + ""; + displayedName.remove(QRegularExpression("/$")); + result = " " + displayedName + " "; return result; } @@ -67,6 +70,16 @@ std::pair HttpServer::splitUserNameAndMessage(const QString &r 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, ""); + lastWbr = i; + } + } + } // http links while (QRegularExpression("(^|\\s)http.?://").match(text).hasMatch()) { int pos = text.indexOf(QRegularExpression("(^|\\s)http.?://")); @@ -100,7 +113,7 @@ std::pair 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, ""); space = i; }