mirror of
https://github.com/KDE/konsole.git
synced 2025-12-23 23:38:08 -05:00
Add URL test cases in HotSpotFilterTest
Add test cases for URLs ending with invalid characters like comma, dot, colon, and semicolon.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
#include "HotSpotFilterTest.h"
|
||||
#include "filterHotSpots/HotSpot.h"
|
||||
#include <QTest>
|
||||
|
||||
QTEST_GUILESS_MAIN(HotSpotFilterTest)
|
||||
@@ -95,6 +96,8 @@ void HotSpotFilterTest::testUrlFilterRegex_data()
|
||||
|
||||
QTest::newRow("query_with_question_marks") << "ldap://[2001:db8::7]/c=GB?objectClass?one"
|
||||
<< "ldap://[2001:db8::7]/c=GB?objectClass?one" << true;
|
||||
QTest::newRow("two_fragments") << "https://example.com#1#2"
|
||||
<< "https://example.com#1" << true;
|
||||
|
||||
QTest::newRow("path_with_parens") << "https://en.wikipedia.org/wiki/C_(programming_language)"
|
||||
<< "https://en.wikipedia.org/wiki/C_(programming_language)" << true;
|
||||
@@ -122,4 +125,78 @@ void HotSpotFilterTest::testUrlFilterRegex()
|
||||
}
|
||||
}
|
||||
|
||||
void HotSpotFilterTest::testUrlFilter_data()
|
||||
{
|
||||
QTest::addColumn<QString>("url");
|
||||
QTest::addColumn<QString>("expectedUrl");
|
||||
QTest::addColumn<bool>("matchResult");
|
||||
|
||||
// If no invalid character is found at the end, the resultUrl should equal the FullUrlRegExp match.
|
||||
QTest::newRow("url_simple") << " https://api.kde.org"
|
||||
<< "https://api.kde.org" << true;
|
||||
QTest::newRow("url_with_port") << "\nhttps://api.kde.org:2098"
|
||||
<< "https://api.kde.org:2098" << true;
|
||||
QTest::newRow("empty_query") << "http://example.com/?"
|
||||
<< "http://example.com/?" << true;
|
||||
QTest::newRow("empty_fragment") << "http://example.com/#"
|
||||
<< "http://example.com/#" << true;
|
||||
QTest::newRow("url_all_bells") << " https://user:pass@api.kde.org:2098/path/to/somewhere?somequery=foo#fragment"
|
||||
<< "https://user:pass@api.kde.org:2098/path/to/somewhere?somequery=foo#fragment" << true;
|
||||
|
||||
// with an invalid character at the end
|
||||
QTest::newRow("url_with_single_quote_end") << "https://example.com'"
|
||||
<< "https://example.com" << true;
|
||||
QTest::newRow("url_with_comma_end") << "https://example.com,"
|
||||
<< "https://example.com" << true;
|
||||
QTest::newRow("url_with_dot_end") << "https://example.com."
|
||||
<< "https://example.com" << true;
|
||||
QTest::newRow("url_with_colon_end") << "https://example.com/:"
|
||||
<< "https://example.com/" << true;
|
||||
QTest::newRow("url_with_semicolon_end") << "https://example.com;"
|
||||
<< "https://example.com" << true;
|
||||
|
||||
// complex cases
|
||||
QTest::newRow("url_with_double_dot_end") << "https://example.com.."
|
||||
<< "https://example.com" << true;
|
||||
QTest::newRow("url_with_dot_start_and_end") << ".https://example.com."
|
||||
<< "https://example.com" << true;
|
||||
QTest::newRow("url_with_single_quote_comma_end") << "'https://example.com',"
|
||||
<< "https://example.com" << true;
|
||||
QTest::newRow("url_with_double_quote_comma_end") << "\"https://example.com\","
|
||||
<< "https://example.com" << true;
|
||||
QTest::newRow("url_with_single_quote_inside") << "'https://en.wikipedia.org/wiki/Earth's_rotation',"
|
||||
<< "https://en.wikipedia.org/wiki/Earth's_rotation" << true;
|
||||
}
|
||||
|
||||
void HotSpotFilterTest::testUrlFilter()
|
||||
{
|
||||
QFETCH(QString, url);
|
||||
QFETCH(QString, expectedUrl);
|
||||
QFETCH(bool, matchResult);
|
||||
|
||||
const QRegularExpression ®ex = Konsole::UrlFilter::FullUrlRegExp;
|
||||
const QRegularExpressionMatch match = regex.match(url);
|
||||
// qDebug() << match;
|
||||
|
||||
QCOMPARE(match.hasMatch(), matchResult);
|
||||
if (matchResult) {
|
||||
auto capturedText = match.capturedTexts()[0];
|
||||
|
||||
// The capturedText is placed at the location from (0, 0) to (0, length).
|
||||
// After processing, the resulting position is extracted to obtain resultUrl.
|
||||
int startLine = 0;
|
||||
int startColumn = 0;
|
||||
int endLine = 0;
|
||||
int endColumn = capturedText.length();
|
||||
|
||||
QSharedPointer<Konsole::HotSpot> hotSpot = Konsole::UrlFilter().newHotSpot(startLine, startColumn, endLine, endColumn, match.capturedTexts());
|
||||
|
||||
int resultStartColumn = hotSpot->startColumn();
|
||||
int resultEndColumn = hotSpot->endColumn();
|
||||
|
||||
QString resultUrl = capturedText.mid(resultStartColumn, resultEndColumn - resultStartColumn);
|
||||
QCOMPARE(resultUrl, expectedUrl);
|
||||
}
|
||||
}
|
||||
|
||||
#include "moc_HotSpotFilterTest.cpp"
|
||||
|
||||
@@ -16,6 +16,9 @@ class HotSpotFilterTest : public QObject
|
||||
private Q_SLOTS:
|
||||
void testUrlFilterRegex_data();
|
||||
void testUrlFilterRegex();
|
||||
|
||||
void testUrlFilter_data();
|
||||
void testUrlFilter();
|
||||
};
|
||||
|
||||
#endif // HOTSPOTFILTERTEST_H
|
||||
|
||||
@@ -21,7 +21,6 @@ class KONSOLEPRIVATE_EXPORT UrlFilter : public RegExpFilter
|
||||
public:
|
||||
UrlFilter();
|
||||
|
||||
protected:
|
||||
QSharedPointer<HotSpot> newHotSpot(int beginRow, int beginColumn, int endRow, int endColumn, const QStringList &list) override;
|
||||
|
||||
public:
|
||||
|
||||
@@ -249,6 +249,18 @@ xmpp:ogoffart@kde.org
|
||||
'https://en.wikipedia.org/wiki/Earths_rotation'
|
||||
"https://en.wikipedia.org/wiki/Earth's_rotation"
|
||||
|
||||
https://example.com'
|
||||
https://example.com,
|
||||
https://example.com.
|
||||
https://example.com/:
|
||||
https://example.com;
|
||||
|
||||
https://example.com..
|
||||
.https://example.com.
|
||||
'https://example.com',
|
||||
"https://example.com",
|
||||
'https://en.wikipedia.org/wiki/Earth's_rotation',
|
||||
|
||||
# testing edge cases - if 80 columns
|
||||
http://www.website.com/directory/relative.html?query=test&name=harry http://www.website.com/directory/relative.html?query=test&name=harryhttp://www.website.com/directory/relative.html?query=test&name=harry
|
||||
--------------
|
||||
|
||||
Reference in New Issue
Block a user