fix: disallow more characters in links (#5509)

This commit is contained in:
nerix
2024-07-20 12:06:23 +02:00
committed by GitHub
parent b3c09b65d8
commit 4a7a5b09ce
3 changed files with 43 additions and 5 deletions
+15
View File
@@ -148,6 +148,16 @@ void strip(QStringView &source)
}
}
/// @brief Checks if @a c is valid in a domain
///
/// Valid characters are 0-9, A-Z, a-z, '-', '_', and '.' (like in GFM)
/// and all non-ASCII characters (unlike in GFM).
Q_ALWAYS_INLINE bool isValidDomainChar(char16_t c)
{
return c >= 0x80 || (u'0' <= c && c <= u'9') || (u'A' <= c && c <= u'Z') ||
(u'a' <= c && c <= u'z') || c == u'_' || c == u'-' || c == u'.';
}
} // namespace
namespace chatterino::linkparser {
@@ -233,6 +243,11 @@ std::optional<Parsed> parse(const QString &source) noexcept
rest = remaining.mid(i);
break;
}
if (!isValidDomainChar(currentChar))
{
return result;
}
}
if (lastWasDot || lastDotPos <= 0)