From 0f2d392b4ba4d72fddc698b0aac9b011f3c21489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Acid=20Chicken=20=28=E7=A1=AB=E9=85=B8=E9=B6=8F=29?= Date: Sun, 22 Sep 2019 01:21:45 +0900 Subject: [PATCH] Use stringz.length instead of String.length in hashtag length calculation (#5443) * Use stringz.length instead of String.length * length to 128, ignore combining --- src/mfm/language.ts | 2 +- src/services/note/create.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mfm/language.ts b/src/mfm/language.ts index 53c275342b..5faa08fd9e 100644 --- a/src/mfm/language.ts +++ b/src/mfm/language.ts @@ -148,7 +148,7 @@ export const mfmLanguage = P.createLanguage({ 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 (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 })); }), url: () => { diff --git a/src/services/note/create.ts b/src/services/note/create.ts index 0dd0e1962f..fcf991793b 100644 --- a/src/services/note/create.ts +++ b/src/services/note/create.ts @@ -165,7 +165,7 @@ export default async (user: User, data: Option, silent = false) => new Promise 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)) { mentionedUsers.push(await Users.findOne(data.reply.userId).then(ensure));