Merge branch 'master' of https://github.com/fourtf/chatterino2
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
#include "common/LinkParser.hpp"
|
||||
|
||||
#include <QFile>
|
||||
#include <QRegularExpression>
|
||||
#include <QString>
|
||||
#include <QTextStream>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
LinkParser::LinkParser(const QString &unparsedString)
|
||||
{
|
||||
static QRegularExpression linkRegex = [] {
|
||||
QFile tldFile(":/tlds.txt");
|
||||
tldFile.open(QFile::ReadOnly);
|
||||
|
||||
QTextStream t1(&tldFile);
|
||||
t1.setCodec("UTF-8");
|
||||
|
||||
// Read the TLDs in and replace the newlines with pipes
|
||||
QString tldData = t1.readAll().replace("\n", "|");
|
||||
|
||||
const QString urlRegExp =
|
||||
"^"
|
||||
// protocol identifier
|
||||
"(?:(?:https?|ftps?)://)?"
|
||||
// user:pass authentication
|
||||
"(?:\\S+(?::\\S*)?@)?"
|
||||
"(?:"
|
||||
// IP address dotted notation octets
|
||||
// excludes loopback network 0.0.0.0
|
||||
// excludes reserved space >= 224.0.0.0
|
||||
// excludes network & broacast addresses
|
||||
// (first & last IP address of each class)
|
||||
"(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])"
|
||||
"(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}"
|
||||
"(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))"
|
||||
"|"
|
||||
// host name
|
||||
"(?:(?:[_a-z\\x{00a1}-\\x{ffff}0-9]-*)*[a-z\\x{00a1}-\\x{ffff}0-9]+)"
|
||||
// domain name
|
||||
"(?:\\.(?:[a-z\\x{00a1}-\\x{ffff}0-9]-*)*[a-z\\x{00a1}-\\x{ffff}0-9]+)*"
|
||||
// TLD identifier
|
||||
//"(?:\\.(?:[a-z\\x{00a1}-\\x{ffff}]{2,}))"
|
||||
"(?:[\\.](?:" +
|
||||
tldData +
|
||||
"))"
|
||||
"\\.?"
|
||||
")"
|
||||
// port number
|
||||
"(?::\\d{2,5})?"
|
||||
// resource path
|
||||
"(?:[/?#]\\S*)?"
|
||||
"$";
|
||||
|
||||
return QRegularExpression(urlRegExp, QRegularExpression::CaseInsensitiveOption);
|
||||
}();
|
||||
|
||||
this->match_ = linkRegex.match(unparsedString);
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include <QRegularExpressionMatch>
|
||||
#include <QString>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class LinkParser
|
||||
{
|
||||
public:
|
||||
explicit LinkParser(const QString &unparsedString);
|
||||
|
||||
bool hasMatch() const
|
||||
{
|
||||
return this->match_.hasMatch();
|
||||
}
|
||||
|
||||
QString getCaptured() const
|
||||
{
|
||||
return this->match_.captured();
|
||||
}
|
||||
|
||||
private:
|
||||
QRegularExpressionMatch match_;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
+9
-1
@@ -23,6 +23,10 @@
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#ifdef C_USE_BREAKPAD
|
||||
#include <QBreakpadHandler.h>
|
||||
#endif
|
||||
|
||||
int runGui(QApplication &a, int argc, char *argv[]);
|
||||
void runNativeMessagingHost();
|
||||
void installCustomPalette();
|
||||
@@ -83,12 +87,16 @@ int runGui(QApplication &a, int argc, char *argv[])
|
||||
|
||||
app->construct();
|
||||
|
||||
#ifdef C_USE_BREAKPAD
|
||||
QBreakpadInstance.setDumpPath(app->paths->settingsFolderPath + "/Crashes");
|
||||
#endif
|
||||
|
||||
auto &pathMan = *app->paths;
|
||||
// Running file
|
||||
auto runningPath = pathMan.miscDirectory + "/running_" + pathMan.applicationFilePathHash;
|
||||
|
||||
if (QFile::exists(runningPath)) {
|
||||
#ifndef DISABLE_CRASH_DIALOG
|
||||
#ifndef C_DISABLE_CRASH_DIALOG
|
||||
chatterino::LastRunCrashDialog dialog;
|
||||
|
||||
switch (dialog.exec()) {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#include "MessageBuilder.hpp"
|
||||
|
||||
#include "common/LinkParser.hpp"
|
||||
#include "singletons/EmoteManager.hpp"
|
||||
#include "singletons/ResourceManager.hpp"
|
||||
#include "singletons/ThemeManager.hpp"
|
||||
@@ -43,19 +45,21 @@ void MessageBuilder::appendTimestamp(const QTime &time)
|
||||
|
||||
QString MessageBuilder::matchLink(const QString &string)
|
||||
{
|
||||
static QRegularExpression linkRegex("[[:ascii:]]*\\.[a-zA-Z]+\\/?[[:ascii:]]*");
|
||||
LinkParser linkParser(string);
|
||||
|
||||
static QRegularExpression httpRegex("\\bhttps?://");
|
||||
static QRegularExpression ftpRegex("\\bftps?://");
|
||||
|
||||
auto match = linkRegex.match(string);
|
||||
|
||||
if (!match.hasMatch()) {
|
||||
if (!linkParser.hasMatch()) {
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString captured = match.captured();
|
||||
QString captured = linkParser.getCaptured();
|
||||
|
||||
if (!captured.contains(httpRegex)) {
|
||||
captured.insert(0, "http://");
|
||||
if (!captured.contains(ftpRegex)) {
|
||||
captured.insert(0, "http://");
|
||||
}
|
||||
}
|
||||
|
||||
return captured;
|
||||
|
||||
Reference in New Issue
Block a user