fix for search request in main page /

master
const an teen 2021-12-06 01:58:01 -05:00
parent f6c1d02351
commit a83df8b12c
1 changed files with 8 additions and 1 deletions

View File

@ -145,6 +145,7 @@ QString HttpServer::getRequestPath(const QString &req)
if (req.isEmpty()) return QString(); if (req.isEmpty()) return QString();
QString result(req); QString result(req);
int begin = result.indexOf(' '); int begin = result.indexOf(' ');
if (begin == -1) return QString(); if (begin == -1) return QString();
@ -161,6 +162,7 @@ QString HttpServer::getRequestPath(const QString &req)
QString HttpServer::getWordFromPath(const QString &path) QString HttpServer::getWordFromPath(const QString &path)
{ {
QString result {path}; QString result {path};
result.remove(QRegularExpression("\\?.*$")); // any actions like a ?toSearch=
if (result.startsWith('/')) { if (result.startsWith('/')) {
result.remove(QRegularExpression("^/")); result.remove(QRegularExpression("^/"));
} }
@ -181,6 +183,12 @@ void HttpServer::replaceTag(QString &page, const QString &tag, const QString &pa
void HttpServer::writeMainPage(QTcpSocket *socket, QString &urlPath) void HttpServer::writeMainPage(QTcpSocket *socket, QString &urlPath)
{ {
QString searchRequest;
int specSymbol = urlPath.indexOf('?'); // any actions like a ?toSearch=
if (specSymbol != -1) {
searchRequest = global::getValue(urlPath, "toSearch", global::eForWeb);
urlPath.remove(specSymbol, urlPath.size()-specSymbol);
}
if (urlPath == "/") { if (urlPath == "/") {
urlPath += m_mainChannel; urlPath += m_mainChannel;
} }
@ -382,7 +390,6 @@ void HttpServer::writeMainPage(QTcpSocket *socket, QString &urlPath)
//// Main section body compilation //// Main section body compilation
QString payloadBlock; QString payloadBlock;
QString searchRequest = global::getValue(urlPath, "toSearch", global::eForWeb);
// Search request // Search request
if (not searchRequest.isEmpty()) { if (not searchRequest.isEmpty()) {
QRegularExpression userRgx(searchRequest, QRegularExpression::CaseInsensitiveOption); QRegularExpression userRgx(searchRequest, QRegularExpression::CaseInsensitiveOption);