mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Format
This commit is contained in:
parent
d6873ad05d
commit
3c72fc867c
|
@ -129,10 +129,13 @@ std::vector<UnicodeRange> alphaNumeric = {
|
||||||
{U'\u0030', U'\u0039'}, // Numbers
|
{U'\u0030', U'\u0039'}, // Numbers
|
||||||
};
|
};
|
||||||
|
|
||||||
bool isInUnicodeRange(const QChar& ch, std::vector<UnicodeRange> ranges) {
|
bool isInUnicodeRange(const QChar &ch, std::vector<UnicodeRange> ranges)
|
||||||
|
{
|
||||||
ushort unicodeValue = ch.unicode();
|
ushort unicodeValue = ch.unicode();
|
||||||
for (const auto& range : ranges) {
|
for (const auto &range : ranges)
|
||||||
if (unicodeValue >= range.first && unicodeValue <= range.second) {
|
{
|
||||||
|
if (unicodeValue >= range.first && unicodeValue <= range.second)
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,7 +150,8 @@ QString sanitizeUrl(const QString &unparsedString)
|
||||||
QString sanitizedUrl;
|
QString sanitizedUrl;
|
||||||
for (const QChar &c : unparsedString)
|
for (const QChar &c : unparsedString)
|
||||||
{
|
{
|
||||||
if (isInUnicodeRange(c, alphaNumeric) || isInUnicodeRange(c, emojiRanges))
|
if (isInUnicodeRange(c, alphaNumeric) ||
|
||||||
|
isInUnicodeRange(c, emojiRanges))
|
||||||
{
|
{
|
||||||
sanitizedUrl.append(c);
|
sanitizedUrl.append(c);
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -34,9 +34,11 @@ struct SanitizeCheck {
|
||||||
TEST(LinkParser, parseDomainLinks)
|
TEST(LinkParser, parseDomainLinks)
|
||||||
{
|
{
|
||||||
const QList<SanitizeCheck> sanitizeCases = {
|
const QList<SanitizeCheck> sanitizeCases = {
|
||||||
{ "TW❘TCH.tv", "TW❘TCH.tv" "" }, // contains dingbat
|
{"TW❘TCH.tv", "TW❘TCH.tv"
|
||||||
|
""}, // contains dingbat
|
||||||
{"(twitch.tv/foo)", "twitch.tv", "/foo"},
|
{"(twitch.tv/foo)", "twitch.tv", "/foo"},
|
||||||
{"t🤪w🤪i🤪t🤪c🤪h🤪.tv/foo", "t🤪w🤪i🤪t🤪c🤪h🤪.tv", "/foo" },
|
{"t🤪w🤪i🤪t🤪c🤪h🤪.tv/foo",
|
||||||
|
"t🤪w🤪i🤪t🤪c🤪h🤪.tv", "/foo"},
|
||||||
{"https://🏹.to/bar", "🏹.to", "/bar"},
|
{"https://🏹.to/bar", "🏹.to", "/bar"},
|
||||||
{"😀.com/baz", "😀.com", "/baz"}, // Emoticon
|
{"😀.com/baz", "😀.com", "/baz"}, // Emoticon
|
||||||
{"❀.com/baz", "❀.com", "/baz"}, // Dingbat
|
{"❀.com/baz", "❀.com", "/baz"}, // Dingbat
|
||||||
|
@ -50,7 +52,8 @@ TEST(LinkParser, parseDomainLinks)
|
||||||
ASSERT_TRUE(p.result().has_value()) << c.testValue.toStdString();
|
ASSERT_TRUE(p.result().has_value()) << c.testValue.toStdString();
|
||||||
const auto &r = *p.result();
|
const auto &r = *p.result();
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
ss << "Expected: " << c.expectedHost.toStdString() << "\nResult: " << r.host.toString().toStdString();
|
ss << "Expected: " << c.expectedHost.toStdString()
|
||||||
|
<< "\nResult: " << r.host.toString().toStdString();
|
||||||
ASSERT_EQ(c.expectedHost, r.host) << ss.str();
|
ASSERT_EQ(c.expectedHost, r.host) << ss.str();
|
||||||
ASSERT_EQ(c.expectedRest, r.rest) << c.expectedRest.toStdString();
|
ASSERT_EQ(c.expectedRest, r.rest) << c.expectedRest.toStdString();
|
||||||
}
|
}
|
||||||
|
@ -160,7 +163,8 @@ TEST(LinkParser, doesntParseInvalidIpv4Links)
|
||||||
|
|
||||||
TEST(LinkParser, doesntParseInvalidLinks)
|
TEST(LinkParser, doesntParseInvalidLinks)
|
||||||
{
|
{
|
||||||
const QStringList inputs = {"h://foo.com",
|
const QStringList inputs = {
|
||||||
|
"h://foo.com",
|
||||||
"spotify:1234",
|
"spotify:1234",
|
||||||
"ftp://chatterino.com",
|
"ftp://chatterino.com",
|
||||||
"ftps://chatterino.com",
|
"ftps://chatterino.com",
|
||||||
|
|
Loading…
Reference in a new issue