Add lists of valid and invalid links

This commit is contained in:
Rasmus Karlsson 2019-12-29 15:45:52 +01:00
parent 17ff0b9d83
commit 25a2c04b02
3 changed files with 192 additions and 1 deletions

View file

@ -441,6 +441,7 @@ HEADERS += \
src/util/RapidJsonSerializeQString.hpp \
src/util/RemoveScrollAreaBackground.hpp \
src/util/SampleCheerMessages.hpp \
src/util/SampleLinks.hpp \
src/util/SharedPtrElementLess.hpp \
src/util/Shortcut.hpp \
src/util/StandardItemHelper.hpp \

174
src/util/SampleLinks.hpp Normal file
View file

@ -0,0 +1,174 @@
#pragma once
#include <QStringList>
namespace chatterino {
QStringList getValidLinks()
{
return {
R"(http://github.com/)",
R"(https://github.com/)",
R"(http://username@github.com/)",
R"(https://username@github.com/)",
R"(http://pajlada.github.io)",
R"(https://pajlada.github.io)",
R"(http://pajlada.github.io/)",
R"(https://pajlada.github.io/)",
R"(http://github.com/some/random/path)",
R"(https://github.com/some/random/path)",
R"(http://github.com?query=value)",
R"(https://github.com?query=value)",
R"(http://github.com?query=value&abc=123)",
R"(https://github.com?query=value&abc=123)",
R"(http://github.com/?query=value&abc=123&yhf=abc_def)",
R"(http://github.com/?query=value&abc=123&yhf)",
R"(http://github.com?query=value&abc=)",
R"(http://github.com?query=value&abc=)",
R"(http://github.com/#block)",
R"(https://github.com/#anchor)",
R"(http://github.com/path/?qs=true#block)",
R"(https://github.com/path/?qs=true#anchor)",
R"(github.com/)",
R"(username@github.com/)",
R"(pajlada.github.io)",
R"(pajlada.github.io/)",
R"(github.com/some/random/path)",
R"(github.com?query=value)",
R"(github.com?query=value&abc=123)",
R"(github.com/?query=value&abc=123&yhf=abc_def)",
R"(github.com/?query=value&abc=123&yhf)",
R"(github.com?query=value&abc=)",
R"(github.com?query=value&abc=)",
R"(github.com/#block)",
R"(github.com/path/?qs=true#block)",
R"(HTTP://GITHUB.COM/)",
R"(HTTPS://GITHUB.COM/)",
R"(HTTP://USERNAME@GITHUB.COM/)",
R"(HTTPS://USERNAME@GITHUB.COM/)",
R"(HTTP://PAJLADA.GITHUB.IO)",
R"(HTTPS://PAJLADA.GITHUB.IO)",
R"(HTTP://PAJLADA.GITHUB.IO/)",
R"(HTTPS://PAJLADA.GITHUB.IO/)",
R"(HTTP://GITHUB.COM/SOME/RANDOM/PATH)",
R"(HTTPS://GITHUB.COM/SOME/RANDOM/PATH)",
R"(HTTP://GITHUB.COM?QUERY=VALUE)",
R"(HTTPS://GITHUB.COM?QUERY=VALUE)",
R"(HTTP://GITHUB.COM?QUERY=VALUE&ABC=123)",
R"(HTTPS://GITHUB.COM?QUERY=VALUE&ABC=123)",
R"(HTTP://GITHUB.COM/?QUERY=VALUE&ABC=123&YHF=ABC_DEF)",
R"(HTTP://GITHUB.COM/?QUERY=VALUE&ABC=123&YHF)",
R"(HTTP://GITHUB.COM?QUERY=VALUE&ABC=)",
R"(HTTP://GITHUB.COM?QUERY=VALUE&ABC=)",
R"(HTTP://GITHUB.COM/#BLOCK)",
R"(HTTPS://GITHUB.COM/#ANCHOR)",
R"(HTTP://GITHUB.COM/PATH/?QS=TRUE#BLOCK)",
R"(HTTPS://GITHUB.COM/PATH/?QS=TRUE#ANCHOR)",
R"(GITHUB.COM/)",
R"(USERNAME@GITHUB.COM/)",
R"(PAJLADA.GITHUB.IO)",
R"(PAJLADA.GITHUB.IO/)",
R"(GITHUB.COM/SOME/RANDOM/PATH)",
R"(GITHUB.COM?QUERY=VALUE)",
R"(GITHUB.COM?QUERY=VALUE&ABC=123)",
R"(GITHUB.COM/?QUERY=VALUE&ABC=123&YHF=ABC_DEF)",
R"(GITHUB.COM/?QUERY=VALUE&ABC=123&YHF)",
R"(GITHUB.COM?QUERY=VALUE&ABC=)",
R"(GITHUB.COM?QUERY=VALUE&ABC=)",
R"(GITHUB.COM/#BLOCK)",
R"(GITHUB.COM/PATH/?QS=TRUE#BLOCK)",
R"(http://foo.com/blah_blah)",
R"(http://foo.com/blah_blah/)",
R"(http://foo.com/blah_blah_(wikipedia))",
R"(http://foo.com/blah_blah_(wikipedia)_(again))",
R"(http://www.example.com/wpstyle/?p=364)",
R"(https://www.example.com/foo/?bar=baz&inga=42&quux)",
R"(http://✪df.ws/123)",
R"(http://userid@example.com)",
R"(http://userid@example.com/)",
R"(http://userid@example.com:8080)",
R"(http://userid@example.com:8080/)",
R"(http://142.42.1.1/)",
R"(http://142.42.1.1:8080/)",
R"(http://➡.ws/䨹)",
R"(http://⌘.ws)",
R"(http://⌘.ws/)",
R"(http://foo.com/blah_(wikipedia)#cite-1)",
R"(http://foo.com/blah_(wikipedia)_blah#cite-1)",
R"(http://foo.com/unicode_(✪)_in_parens)",
R"(http://foo.com/(something)?after=parens)",
R"(http://☺.damowmow.com/)",
R"(http://code.google.com/events/#&product=browser)",
R"(http://j.mp)",
R"(ftp://foo.bar/baz)",
R"(http://foo.bar/?q=Test%20URL-encoded%20stuff)",
R"(http://مثال.إختبار)",
R"(http://例子.测试)",
R"(http://उदाहरण.परीक्षा)",
R"(http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com)",
R"(http://1337.net)",
R"(http://a.b-c.de)",
R"(http://223.255.255.254)",
};
}
QStringList getValidButIgnoredLinks()
{
return {
R"(http://username:password@github.com/)",
R"(https://username:password@github.com/)",
R"(http://userid:password@example.com)",
R"(http://userid:password@example.com/)",
R"(http://userid:password@example.com:8080)",
R"(http://userid:password@example.com:8080/)",
};
}
QStringList getInvalidLinks()
{
return {
R"(1.40)",
R"(test..)",
R"(test.)",
R"(http://)",
R"(http://.)",
R"(http://..)",
R"(http://../)",
R"(http://?)",
R"(http://??)",
R"(http://??/)",
R"(http://#)",
R"(http://##)",
R"(http://##/)",
R"(http://foo.bar?q=Spaces should be encoded)",
R"(//)",
R"(//a)",
R"(///a)",
R"(///)",
R"(http:///a)",
R"(foo.com)",
R"(rdar://1234)",
R"(h://test)",
R"(http:// shouldfail.com)",
R"(:// should fail)",
R"(http://foo.bar/foo(bar)baz quux)",
R"(ftps://foo.bar/)",
R"(http://-error-.invalid/)",
R"(http://a.b--c.de/)",
R"(http://-a.b.co)",
R"(http://a.b-.co)",
R"(http://0.0.0.0)",
R"(http://10.1.1.0)",
R"(http://10.1.1.255)",
R"(http://224.1.1.1)",
R"(http://1.1.1.1.1)",
R"(http://123.123.123)",
R"(http://3628126748)",
R"(http://.www.foo.bar/)",
R"(http://www.foo.bar./)",
R"(http://.www.foo.bar./)",
R"(http://10.1.1.1)",
};
}
} // namespace chatterino

View file

@ -26,6 +26,7 @@
#ifdef C_DEBUG
# include "util/SampleCheerMessages.hpp"
# include "util/SampleLinks.hpp"
#endif
#include <QApplication>
@ -199,9 +200,11 @@ void Window::addCustomTitlebarButtons()
void Window::addDebugStuff()
{
#ifdef C_DEBUG
std::vector<QString> cheerMessages, subMessages, miscMessages;
std::vector<QString> cheerMessages, subMessages, miscMessages, linkMessages;
cheerMessages = getSampleCheerMessage();
auto validLinks = getValidLinks();
auto invalidLinks = getInvalidLinks();
// clang-format off
subMessages.emplace_back(R"(@badges=staff/1,broadcaster/1,turbo/1;color=#008000;display-name=ronni;emotes=;id=db25007f-7a18-43eb-9379-80131e44d633;login=ronni;mod=0;msg-id=resub;msg-param-months=6;msg-param-sub-plan=Prime;msg-param-sub-plan-name=Prime;room-id=1337;subscriber=1;system-msg=ronni\shas\ssubscribed\sfor\s6\smonths!;tmi-sent-ts=1507246572675;turbo=1;user-id=1337;user-type=staff :tmi.twitch.tv USERNOTICE #pajlada :Great stream -- keep it up!)");
@ -231,6 +234,11 @@ void Window::addDebugStuff()
// display name renders strangely
miscMessages.emplace_back(R"(@badges=;color=#00AD2B;display-name=Iamme420\s;emotes=;id=d47a1e4b-a3c6-4b9e-9bf1-51b8f3dbc76e;mod=0;room-id=11148817;subscriber=0;tmi-sent-ts=1529670347537;turbo=0;user-id=56422869;user-type= :iamme420!iamme420@iamme420.tmi.twitch.tv PRIVMSG #pajlada :offline chat gachiBASS)");
miscMessages.emplace_back(R"(@badge-info=founder/47;badges=moderator/1,founder/0,premium/1;color=#00FF80;display-name=gempir;emotes=;flags=;id=d4514490-202e-43cb-b429-ef01a9d9c2fe;mod=1;room-id=11148817;subscriber=0;tmi-sent-ts=1575198233854;turbo=0;user-id=77829817;user-type=mod :gempir!gempir@gempir.tmi.twitch.tv PRIVMSG #pajlada :offline chat gachiBASS)");
// various link tests
linkMessages.emplace_back(R"(@badge-info=subscriber/48;badges=broadcaster/1,subscriber/36,partner/1;color=#CC44FF;display-name=pajlada;emotes=;flags=;id=3c23cf3c-0864-4699-a76b-089350141147;mod=0;room-id=11148817;subscriber=1;tmi-sent-ts=1577628844607;turbo=0;user-id=11148817;user-type= :pajlada!pajlada@pajlada.tmi.twitch.tv PRIVMSG #pajlada : Links that should pass: )" + getValidLinks().join(' '));
linkMessages.emplace_back(R"(@badge-info=subscriber/48;badges=broadcaster/1,subscriber/36,partner/1;color=#CC44FF;display-name=pajlada;emotes=;flags=;id=3c23cf3c-0864-4699-a76b-089350141147;mod=0;room-id=11148817;subscriber=1;tmi-sent-ts=1577628844607;turbo=0;user-id=11148817;user-type= :pajlada!pajlada@pajlada.tmi.twitch.tv PRIVMSG #pajlada : Links that should NOT pass: )" + getInvalidLinks().join(' '));
linkMessages.emplace_back(R"(@badge-info=subscriber/48;badges=broadcaster/1,subscriber/36,partner/1;color=#CC44FF;display-name=pajlada;emotes=;flags=;id=3c23cf3c-0864-4699-a76b-089350141147;mod=0;room-id=11148817;subscriber=1;tmi-sent-ts=1577628844607;turbo=0;user-id=11148817;user-type= :pajlada!pajlada@pajlada.tmi.twitch.tv PRIVMSG #pajlada : Links that should technically pass but we choose not to parse them: )" + getValidButIgnoredLinks().join(' '));
// clang-format on
createWindowShortcut(this, "F6", [=] {
@ -248,6 +256,14 @@ void Window::addDebugStuff()
getApp()->twitch.server->addFakeMessage(msg);
});
createWindowShortcut(this, "F8", [=] {
const auto &messages = linkMessages;
static int index = 0;
auto app = getApp();
const auto &msg = messages[index++ % messages.size()];
app->twitch.server->addFakeMessage(msg);
});
createWindowShortcut(this, "F9", [=] {
auto *dialog = new WelcomeDialog();
dialog->setAttribute(Qt::WA_DeleteOnClose);