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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 5 deletions

View file

@ -6,6 +6,7 @@
- Minor: Added `/shield` and `/shieldoff` commands to toggle shield mode. (#4580)
- Bugfix: Fixed the menu warping on macOS on Qt6. (#4595)
- 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)
- Dev: Added the ability to control the `followRedirect` mode for requests. (#4594)

View file

@ -137,16 +137,18 @@ LinkParser::LinkParser(const QString &unparsedString)
if (remaining.startsWith(QStringLiteral("http"), Qt::CaseInsensitive) &&
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)
result.protocol = {protocol.begin(), remaining.begin()};
#else

View file

@ -48,6 +48,13 @@ TEST(LinkParser, parseDomainLinks)
{"", "1.com"},
{"", "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
{"HtTpS://", "127.0.0.1.CoM"},
{"HTTP://", "XD.CHATTERINO.COM", "/#?FOO"},
@ -146,6 +153,18 @@ TEST(LinkParser, doesntParseInvalidLinks)
"a",
"://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)