Parse Domains Starting With http (#4598)

Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
nerix
2023-05-07 14:15:36 +02:00
committed by GitHub
parent 91f4b86436
commit 280b6d934e
3 changed files with 27 additions and 5 deletions
+1
View File
@@ -6,6 +6,7 @@
- Minor: Added `/shield` and `/shieldoff` commands to toggle shield mode. (#4580) - Minor: Added `/shield` and `/shieldoff` commands to toggle shield mode. (#4580)
- Bugfix: Fixed the menu warping on macOS on Qt6. (#4595) - Bugfix: Fixed the menu warping on macOS on Qt6. (#4595)
- Bugfix: Fixed link tooltips not showing unless the thumbnail setting was enabled. (#4597) - Bugfix: Fixed link tooltips not showing unless the thumbnail setting was enabled. (#4597)
- Bugfix: Domains starting with `http` are now parsed as links again. (#4598)
- Bugfix: Fixed click effects on buttons not being antialiased. (#4473) - Bugfix: Fixed click effects on buttons not being antialiased. (#4473)
- Dev: Added the ability to control the `followRedirect` mode for requests. (#4594) - Dev: Added the ability to control the `followRedirect` mode for requests. (#4594)
+7 -5
View File
@@ -137,16 +137,18 @@ LinkParser::LinkParser(const QString &unparsedString)
if (remaining.startsWith(QStringLiteral("http"), Qt::CaseInsensitive) && if (remaining.startsWith(QStringLiteral("http"), Qt::CaseInsensitive) &&
remaining.length() >= 4 + 3 + 1) // 'http' + '://' + [any] remaining.length() >= 4 + 3 + 1) // 'http' + '://' + [any]
{ {
remaining = remaining.mid(4); // 'http' // optimistic view assuming there's a protocol (http or https)
auto withProto = remaining.mid(4); // 'http'
if (remaining[0] == QChar(u's') || remaining[0] == QChar(u'S')) if (withProto[0] == QChar(u's') || withProto[0] == QChar(u'S'))
{ {
remaining = remaining.mid(1); withProto = withProto.mid(1);
} }
if (remaining.startsWith(QStringLiteral("://"))) if (withProto.startsWith(QStringLiteral("://")))
{ {
remaining = remaining.mid(3); // there's really a protocol => consume it
remaining = withProto.mid(3);
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
result.protocol = {protocol.begin(), remaining.begin()}; result.protocol = {protocol.begin(), remaining.begin()};
#else #else
+19
View File
@@ -48,6 +48,13 @@ TEST(LinkParser, parseDomainLinks)
{"", "1.com"}, {"", "1.com"},
{"", "127.0.0.1.com"}, {"", "127.0.0.1.com"},
{"https://", "127.0.0.1.com"}, {"https://", "127.0.0.1.com"},
{"https://", "http.cat", "/200"},
{"https://", "http.cat"},
{"", "http.cat", ":8080"},
{"", "http.cat"},
{"", "https.cat"},
{"", "httpsd.cat"},
{"", "http.cat", "/200"},
// test case-insensitiveness // test case-insensitiveness
{"HtTpS://", "127.0.0.1.CoM"}, {"HtTpS://", "127.0.0.1.CoM"},
{"HTTP://", "XD.CHATTERINO.COM", "/#?FOO"}, {"HTTP://", "XD.CHATTERINO.COM", "/#?FOO"},
@@ -146,6 +153,18 @@ TEST(LinkParser, doesntParseInvalidLinks)
"a", "a",
"://chatterino.com", "://chatterino.com",
"//chatterino.com", "//chatterino.com",
"http://pn.",
"http://pn./",
"https://pn./",
"pn./",
"pn.",
"http/chatterino.com",
"http/wiki.chatterino.com",
"http:cat.com",
"https:cat.com",
"http:/cat.com",
"http:/cat.com",
"https:/cat.com",
}; };
for (const auto &input : inputs) for (const auto &input : inputs)