Use stringz.length instead of String.length in hashtag length calculation (#5443)

* Use stringz.length instead of String.length

* length to 128, ignore combining
This commit is contained in:
Acid Chicken (硫酸鶏) 2019-09-22 01:21:45 +09:00 committed by syuilo
parent 53fba9b137
commit 0f2d392b4b
2 changed files with 2 additions and 2 deletions

View file

@ -148,7 +148,7 @@ export const mfmLanguage = P.createLanguage({
if (hashtag.match(/^(\u20e3|\ufe0f)/)) return P.makeFailure(i, 'not a hashtag'); if (hashtag.match(/^(\u20e3|\ufe0f)/)) return P.makeFailure(i, 'not a hashtag');
if (hashtag.match(/^[0-9]+$/)) return P.makeFailure(i, 'not a hashtag'); if (hashtag.match(/^[0-9]+$/)) return P.makeFailure(i, 'not a hashtag');
if (input[i - 1] != null && input[i - 1].match(/[a-z0-9]/i)) return P.makeFailure(i, 'not a hashtag'); if (input[i - 1] != null && input[i - 1].match(/[a-z0-9]/i)) return P.makeFailure(i, 'not a hashtag');
if (hashtag.length > 50) return P.makeFailure(i, 'not a hashtag'); if (Array.from(hashtag || '').length > 128) return P.makeFailure(i, 'not a hashtag');
return P.makeSuccess(i + ('#' + hashtag).length, createLeaf('hashtag', { hashtag: hashtag })); return P.makeSuccess(i + ('#' + hashtag).length, createLeaf('hashtag', { hashtag: hashtag }));
}), }),
url: () => { url: () => {

View file

@ -165,7 +165,7 @@ export default async (user: User, data: Option, silent = false) => new Promise<N
mentionedUsers = data.apMentions || await extractMentionedUsers(user, combinedTokens); mentionedUsers = data.apMentions || await extractMentionedUsers(user, combinedTokens);
} }
tags = tags.filter(tag => tag.length <= 100); tags = tags.filter(tag => Array.from(tag || '').length <= 128);
if (data.reply && (user.id !== data.reply.userId) && !mentionedUsers.some(u => u.id === data.reply!.userId)) { if (data.reply && (user.id !== data.reply.userId) && !mentionedUsers.some(u => u.id === data.reply!.userId)) {
mentionedUsers.push(await Users.findOne(data.reply.userId).then(ensure)); mentionedUsers.push(await Users.findOne(data.reply.userId).then(ensure));