mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Intermediate updates of RFC Compliant URL Matching
Just some small changes. Fixing IP range exclusion and fixing ftp link so it doesn't include http:// when you copy it.
This commit is contained in:
parent
848253b015
commit
afaee6ec9c
1 changed files with 5 additions and 7 deletions
|
@ -50,11 +50,6 @@ QString MessageBuilder::matchLink(const QString &string)
|
||||||
// user:pass authentication
|
// user:pass authentication
|
||||||
"(?:\\S+(?::\\S*)?@)?"
|
"(?:\\S+(?::\\S*)?@)?"
|
||||||
"(?:"
|
"(?:"
|
||||||
// IP address exclusion
|
|
||||||
// private & local networks
|
|
||||||
"(?!(?:10|127)(?:\\.\\d{1,3}){3})"
|
|
||||||
"(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})"
|
|
||||||
"(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})"
|
|
||||||
// IP address dotted notation octets
|
// IP address dotted notation octets
|
||||||
// excludes loopback network 0.0.0.0
|
// excludes loopback network 0.0.0.0
|
||||||
// excludes reserved space >= 224.0.0.0
|
// excludes reserved space >= 224.0.0.0
|
||||||
|
@ -80,6 +75,7 @@ QString MessageBuilder::matchLink(const QString &string)
|
||||||
|
|
||||||
static QRegularExpression linkRegex(urlRegExp, QRegularExpression::CaseInsensitiveOption);
|
static QRegularExpression linkRegex(urlRegExp, QRegularExpression::CaseInsensitiveOption);
|
||||||
static QRegularExpression httpRegex("\\bhttps?://");
|
static QRegularExpression httpRegex("\\bhttps?://");
|
||||||
|
static QRegularExpression ftpRegex("\\bftp?://");
|
||||||
auto match = linkRegex.match(string);
|
auto match = linkRegex.match(string);
|
||||||
|
|
||||||
if (!match.hasMatch()) {
|
if (!match.hasMatch()) {
|
||||||
|
@ -89,8 +85,10 @@ QString MessageBuilder::matchLink(const QString &string)
|
||||||
QString captured = match.captured();
|
QString captured = match.captured();
|
||||||
|
|
||||||
if (!captured.contains(httpRegex)) {
|
if (!captured.contains(httpRegex)) {
|
||||||
|
if (!captured.contains(ftpRegex)) {
|
||||||
captured.insert(0, "http://");
|
captured.insert(0, "http://");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return captured;
|
return captured;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue