Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse Domains Starting With http #4598

Merged
merged 4 commits into from
May 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 7 additions & 5 deletions src/common/LinkParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions tests/src/LinkParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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)
Expand Down