From 3c72fc867cfac6d78ac7e93700b19d5bcaaf7f5b Mon Sep 17 00:00:00 2001 From: Colton Clemmer Date: Sun, 3 Sep 2023 10:37:03 -0500 Subject: [PATCH] Format --- src/common/LinkParser.cpp | 28 +++++++----- tests/src/LinkParser.cpp | 96 ++++++++++++++++++++------------------- 2 files changed, 66 insertions(+), 58 deletions(-) diff --git a/src/common/LinkParser.cpp b/src/common/LinkParser.cpp index 607047d19..db389e6f7 100644 --- a/src/common/LinkParser.cpp +++ b/src/common/LinkParser.cpp @@ -116,23 +116,26 @@ bool startsWithPort(QStringView string) // For unicode ranges see: https://unicode.org/charts/ using UnicodeRange = std::pair; std::vector emojiRanges = { - {U'\U00002700', U'\U000027BF' }, // Dingbats - {U'\U00001F60', U'\U0001F64F' }, // Emoticons - {U'\U00002600', U'\U000026FF' }, // Miscellaneous Symbols - {U'\U00001F30', U'\U0001F5FF' }, // Miscellaneous Symbols and Pictographs - {U'\U00001F90', U'\U0001F9FF' }, // Supplemental Symbols and Pictographs + {U'\U00002700', U'\U000027BF'}, // Dingbats + {U'\U00001F60', U'\U0001F64F'}, // Emoticons + {U'\U00002600', U'\U000026FF'}, // Miscellaneous Symbols + {U'\U00001F30', U'\U0001F5FF'}, // Miscellaneous Symbols and Pictographs + {U'\U00001F90', U'\U0001F9FF'}, // Supplemental Symbols and Pictographs }; std::vector alphaNumeric = { - { U'\u0041', U'\u005A' }, // Upper alphabet - { U'\u0061', U'\u007A' }, //Lower alphabet - { U'\u0030', U'\u0039' }, // Numbers + {U'\u0041', U'\u005A'}, // Upper alphabet + {U'\u0061', U'\u007A'}, //Lower alphabet + {U'\u0030', U'\u0039'}, // Numbers }; -bool isInUnicodeRange(const QChar& ch, std::vector ranges) { +bool isInUnicodeRange(const QChar &ch, std::vector ranges) +{ ushort unicodeValue = ch.unicode(); - for (const auto& range : ranges) { - if (unicodeValue >= range.first && unicodeValue <= range.second) { + for (const auto &range : ranges) + { + if (unicodeValue >= range.first && unicodeValue <= range.second) + { return true; } } @@ -147,7 +150,8 @@ QString sanitizeUrl(const QString &unparsedString) QString sanitizedUrl; for (const QChar &c : unparsedString) { - if (isInUnicodeRange(c, alphaNumeric) || isInUnicodeRange(c, emojiRanges)) + if (isInUnicodeRange(c, alphaNumeric) || + isInUnicodeRange(c, emojiRanges)) { sanitizedUrl.append(c); continue; diff --git a/tests/src/LinkParser.cpp b/tests/src/LinkParser.cpp index 85d999b88..18340fbf7 100644 --- a/tests/src/LinkParser.cpp +++ b/tests/src/LinkParser.cpp @@ -34,14 +34,16 @@ struct SanitizeCheck { TEST(LinkParser, parseDomainLinks) { const QList sanitizeCases = { - { "TW❘TCH.tv", "TW❘TCH.tv" "" }, // contains dingbat - {"(twitch.tv/foo)", "twitch.tv", "/foo" }, - {"t🤪w🤪i🤪t🤪c🤪h🤪.tv/foo", "t🤪w🤪i🤪t🤪c🤪h🤪.tv", "/foo" }, - { "https://🏹.to/bar", "🏹.to", "/bar" }, - { "😀.com/baz", "😀.com", "/baz" }, // Emoticon - { "❀.com/baz", "❀.com", "/baz" }, // Dingbat - { "⛑.com/baz", "⛑.com", "/baz" }, // Misc Symbol - { "🍀.com/baz", "🍀.com", "/baz" }, // Pictograph + {"TW❘TCH.tv", "TW❘TCH.tv" + ""}, // contains dingbat + {"(twitch.tv/foo)", "twitch.tv", "/foo"}, + {"t🤪w🤪i🤪t🤪c🤪h🤪.tv/foo", + "t🤪w🤪i🤪t🤪c🤪h🤪.tv", "/foo"}, + {"https://🏹.to/bar", "🏹.to", "/bar"}, + {"😀.com/baz", "😀.com", "/baz"}, // Emoticon + {"❀.com/baz", "❀.com", "/baz"}, // Dingbat + {"⛑.com/baz", "⛑.com", "/baz"}, // Misc Symbol + {"🍀.com/baz", "🍀.com", "/baz"}, // Pictograph }; for (auto &c : sanitizeCases) @@ -50,7 +52,8 @@ TEST(LinkParser, parseDomainLinks) ASSERT_TRUE(p.result().has_value()) << c.testValue.toStdString(); const auto &r = *p.result(); 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.expectedRest, r.rest) << c.expectedRest.toStdString(); } @@ -160,43 +163,44 @@ TEST(LinkParser, doesntParseInvalidIpv4Links) TEST(LinkParser, doesntParseInvalidLinks) { - const QStringList inputs = {"h://foo.com", - "spotify:1234", - "ftp://chatterino.com", - "ftps://chatterino.com", - "spotify://chatterino.com", - "httpsx://chatterino.com", - "https:chatterino.com", - "https:/chatterino.com", - "http:/chatterino.com", - "htp://chatterino.com", - "/chatterino.com", - "word", - ".", - "/", - "#", - ":", - "?", - "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", - "%%%%.com", - "*.com", - "t🤪w🤪i🤪t🤪c🤪h🤪.🤪t🤪v/foo", // Invalid tld - "https։⧸⧸TW❘TCH.tv/a⧸b" // misleading characters: "⧸" and "։" - }; + const QStringList inputs = { + "h://foo.com", + "spotify:1234", + "ftp://chatterino.com", + "ftps://chatterino.com", + "spotify://chatterino.com", + "httpsx://chatterino.com", + "https:chatterino.com", + "https:/chatterino.com", + "http:/chatterino.com", + "htp://chatterino.com", + "/chatterino.com", + "word", + ".", + "/", + "#", + ":", + "?", + "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", + "%%%%.com", + "*.com", + "t🤪w🤪i🤪t🤪c🤪h🤪.🤪t🤪v/foo", // Invalid tld + "https։⧸⧸TW❘TCH.tv/a⧸b" // misleading characters: "⧸" and "։" + }; for (const auto &input : inputs) {