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:
Lajamerr Mittesdine 2018-06-05 09:29:59 -04:00 committed by GitHub
parent 848253b015
commit afaee6ec9c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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,7 +85,9 @@ QString MessageBuilder::matchLink(const QString &string)
QString captured = match.captured(); QString captured = match.captured();
if (!captured.contains(httpRegex)) { if (!captured.contains(httpRegex)) {
captured.insert(0, "http://"); if (!captured.contains(ftpRegex)) {
captured.insert(0, "http://");
}
} }
return captured; return captured;