From f7b389694917b247d75edcae4d9485156ed97afd Mon Sep 17 00:00:00 2001 From: Jesse Litton Date: Thu, 9 Mar 2017 09:30:33 -0600 Subject: [PATCH] Fix some broken logic in KOS checking. --- src/mainwindow.cpp | 59 ++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f6b7db6..fafa879 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -351,38 +351,32 @@ void MainWindow::clipboardUpdated() { if(options.getKosCheck()) { - QStringList names; - if(!QApplication::clipboard()->text().contains('\n')) + QStringList lines, names; + lines = QApplication::clipboard()->text().split('\n'); + + foreach(QString line, lines) { - // Check to see if this is a right-click+Copy from the chat area: + // Sanitize the list if it's copied from chat. i.e.... // Rotham Visteen > Sir Nicolas Struik TU-O0T nv - // J'erat > Lord Helios Sir Nicolas Struik B-WPLZ - // makoto Riraille > nuggt007 JEIV-E* nv - // Ariaphne > Izaq E-YCML nv - // Moon Loop > XHQ-7V* AntarisIX Sabre* - // Vipress X-TAW-SIN > CocoMaster Yung DNR-7M nv - // Khasm Kaotiqa > CocoMaster Yung - // Jophiel Gabriel Sir Nicolas Struik - // Lord Helios - // Rounon Dax > Danilo Audier Jophiel Gabriel - // - JEIV-E - // Khasm Kaotiqa > Koizumi Atsuchi red - // Ars Amatoria > Sith Koroshi Dreadnought group location then? - // Khasm Kaotiqa > N-RMSH Xe4roX - // Khasm Kaotiqa Sir Nicolas Struik - // Khasm Kaotiqa > Sir Nicolas Struik Sir Nicolas Struik + // showinfo:5//... seems to denote a link to a system, pilots will have different numbers QRegularExpression exp("]+>([^<]+)"); - QRegularExpressionMatchIterator i = exp.globalMatch(QApplication::clipboard()->text()); - while(i.hasNext()) + QRegularExpressionMatch match = exp.match(line); + + if(match.hasMatch()) { - QRegularExpressionMatch match = i.next(); - names.append(match.captured(1)); + QRegularExpressionMatchIterator i = exp.globalMatch(QApplication::clipboard()->text()); + while(i.hasNext()) + { + match = i.next(); + names.append(match.captured(1)); + } + } + else + { + // Doesn't look like a copied line with markup, so just append it unsanitized. + names.append(line); } - } - else - { - names = QApplication::clipboard()->text().split('\n'); } QStringList toCheck; @@ -392,7 +386,7 @@ void MainWindow::clipboardUpdated() if(name.length() < 3 || name.length() > 37 || name.count(QLatin1Char(' ')) > 2 || - name.contains(QRegExp("^[^ A-Za-z0-9'\\-\\.]+$"))) + name.contains(QRegExp("[^ A-Za-z0-9'\\-\\.]"))) { qDebug() << "MainWindow::clipboardUpdated() - Not KOS checking invalid name " << name; return; @@ -404,10 +398,13 @@ void MainWindow::clipboardUpdated() } QString checkString = toCheck.join(','); - AsyncInfo* kosInfo = new AsyncInfo(manager, this); - connect(kosInfo, SIGNAL(kosResultReady(const QList&)), - this, SLOT(gotKosReply(const QList&))); - kosInfo->kosCheck(checkString); + if(checkString != "") + { + AsyncInfo* kosInfo = new AsyncInfo(manager, this); + connect(kosInfo, SIGNAL(kosResultReady(const QList&)), + this, SLOT(gotKosReply(const QList&))); + kosInfo->kosCheck(checkString); + } } }