1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Merge pull request #4279

noavarice (2):
      test: added case for multiple URL's in one message
      fix: fixed wrong formatting for multiple URL's in one message
This commit is contained in:
sudden6 2017-03-23 13:35:22 +01:00
commit feea196ad2
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
2 changed files with 22 additions and 1 deletions

View File

@ -150,14 +150,17 @@ static bool isTagIntersection(const QString& str)
*/ */
static void processUrl(QString& str, std::function<QString(QString&)> func) static void processUrl(QString& str, std::function<QString(QString&)> func)
{ {
int startLength = str.length();
int offset = 0;
for (QRegularExpression exp : urlPatterns) { for (QRegularExpression exp : urlPatterns) {
QRegularExpressionMatchIterator iter = exp.globalMatch(str); QRegularExpressionMatchIterator iter = exp.globalMatch(str);
while (iter.hasNext()) { while (iter.hasNext()) {
QRegularExpressionMatch match = iter.next(); QRegularExpressionMatch match = iter.next();
int startPos = match.capturedStart(); int startPos = match.capturedStart() + offset;
int length = match.capturedLength(); int length = match.capturedLength();
QString url = str.mid(startPos, length); QString url = str.mid(startPos, length);
str.replace(startPos, length, func(url)); str.replace(startPos, length, func(url));
offset = str.length() - startLength;
} }
} }
} }

View File

@ -96,6 +96,24 @@ static const StringToString urlCases {
{QStringLiteral("https://url.com/some`url/some`more`url/"), {QStringLiteral("https://url.com/some`url/some`more`url/"),
QStringLiteral("<a href=\"https://url.com/some`url/some`more`url/\">" QStringLiteral("<a href=\"https://url.com/some`url/some`more`url/\">"
"https://url.com/some`url/some`more`url/</a>")}, "https://url.com/some`url/some`more`url/</a>")},
// Test case from issue #4275
{QStringLiteral("http://www.metacritic.com/game/pc/mass-effect-andromeda\n"
"http://www.metacritic.com/game/playstation-4/mass-effect-andromeda\n"
"http://www.metacritic.com/game/xbox-one/mass-effect-andromeda"),
QStringLiteral("<a href=\"http://www.metacritic.com/game/pc/mass-effect-andromeda\">"
"http://www.metacritic.com/game/pc/mass-effect-andromeda</a>\n"
"<a href=\"http://www.metacritic.com/game/playstation-4/mass-effect-andromeda\""
">http://www.metacritic.com/game/playstation-4/mass-effect-andromeda</a>\n"
"<a href=\"http://www.metacritic.com/game/xbox-one/mass-effect-andromeda\">"
"http://www.metacritic.com/game/xbox-one/mass-effect-andromeda</a>")},
{QStringLiteral("http://site.com/part1/part2 "
"http://site.com/part3 "
"and one more time "
"www.site.com/part1/part2"),
QStringLiteral("<a href=\"http://site.com/part1/part2\">http://site.com/part1/part2</a> "
"<a href=\"http://site.com/part3\">http://site.com/part3</a> "
"and one more time "
"<a href=\"http://www.site.com/part1/part2\">www.site.com/part1/part2</a>")},
}; };
/** /**