Disallow hashtags of digits only.

This commit is contained in:
John Preston 2018-03-06 18:29:45 +03:00
parent 0f901b3728
commit 7940ef24ab
4 changed files with 27 additions and 2 deletions

View File

@ -2487,12 +2487,16 @@ void DialogsInner::saveRecentHashtags(const QString &text) {
--next;
}
}
const auto tag = text.mid(i + 1, next - i - 1);
if (TextUtilities::RegExpHashtagExclude().match(tag).hasMatch()) {
continue;
}
if (!found && cRecentWriteHashtags().isEmpty() && cRecentSearchHashtags().isEmpty()) {
Local::readRecentHashtagsAndBots();
recent = cRecentSearchHashtags();
}
found = true;
Stickers::IncrementRecentHashtag(recent, text.mid(i + 1, next - i - 1));
Stickers::IncrementRecentHashtag(recent, tag);
}
if (found) {
cSetRecentSearchHashtags(recent);

View File

@ -1365,12 +1365,16 @@ void MainWidget::saveRecentHashtags(const QString &text) {
--next;
}
}
const auto tag = text.mid(i + 1, next - i - 1);
if (TextUtilities::RegExpHashtagExclude().match(tag).hasMatch()) {
continue;
}
if (!found && cRecentWriteHashtags().isEmpty() && cRecentSearchHashtags().isEmpty()) {
Local::readRecentHashtagsAndBots();
recent = cRecentWriteHashtags();
}
found = true;
Stickers::IncrementRecentHashtag(recent, text.mid(i + 1, next - i - 1));
Stickers::IncrementRecentHashtag(recent, tag);
}
if (found) {
cSetRecentWriteHashtags(recent);

View File

@ -40,6 +40,10 @@ QString ExpressionHashtag() {
return qsl("(^|[") + ExpressionSeparators(qsl("`\\*/")) + qsl("])#[\\w]{2,64}([\\W]|$)");
}
QString ExpressionHashtagExclude() {
return qsl("^#?\\d+$");
}
QString ExpressionMention() {
return qsl("(^|[") + ExpressionSeparators(qsl("`\\*/")) + qsl("])@[A-Za-z_0-9]{1,32}([\\W]|$)");
}
@ -1141,6 +1145,11 @@ const QRegularExpression &RegExpHashtag() {
return result;
}
const QRegularExpression &RegExpHashtagExclude() {
static const auto result = CreateRegExp(ExpressionHashtagExclude());
return result;
}
const QRegularExpression &RegExpMention() {
static const auto result = CreateRegExp(ExpressionMention());
return result;
@ -1844,6 +1853,13 @@ void ParseEntities(TextWithEntities &result, int32 flags, bool rich) {
if (!mHashtag.capturedRef(2).isEmpty()) {
--hashtagEnd;
}
if (RegExpHashtagExclude().match(
result.text.mid(
hashtagStart + 1,
hashtagEnd - hashtagStart - 1)).hasMatch()) {
hashtagStart = INT_MAX;
hashtagEnd = INT_MAX;
}
}
while (mMention.hasMatch()) {
if (!mMention.capturedRef(1).isEmpty()) {

View File

@ -160,6 +160,7 @@ const QRegularExpression &RegExpDomain();
const QRegularExpression &RegExpDomainExplicit();
const QRegularExpression &RegExpMailNameAtEnd();
const QRegularExpression &RegExpHashtag();
const QRegularExpression &RegExpHashtagExclude();
const QRegularExpression &RegExpMention();
const QRegularExpression &RegExpBotCommand();
const QRegularExpression &RegExpMarkdownBold();