From 92708d2f6b275e3afa41b228f4f91c87caf6e938 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 18 Feb 2025 10:56:56 -0500 Subject: [PATCH] fix: #13170, remove mime-type and regex test for "Emoji" attachment, wrap tag name in colons if not provided --- src/posts/create.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/posts/create.js b/src/posts/create.js index 869fdf3a05..656ae68ab0 100644 --- a/src/posts/create.js +++ b/src/posts/create.js @@ -11,8 +11,6 @@ const privileges = require('../privileges'); const activitypub = require('../activitypub'); const utils = require('../utils'); -const isEmojiShortcode = /^:[\w]+:$/; - module.exports = function (Posts) { Posts.create = async function (data) { // This is an internal method, consider using Topics.reply instead @@ -54,9 +52,15 @@ module.exports = function (Posts) { if (_activitypub && _activitypub.tag && Array.isArray(_activitypub.tag)) { _activitypub.tag .filter(tag => tag.type === 'Emoji' && - isEmojiShortcode.test(tag.name) && - tag.icon && tag.icon.mediaType && tag.icon.mediaType.startsWith('image/')) + tag.icon && tag.icon.type === 'Image') .forEach((tag) => { + if (!tag.name.startsWith(':')) { + tag.name = `:${tag.name}`; + } + if (!tag.name.endsWith(':')) { + tag.name = `${tag.name}:`; + } + postData.content = postData.content.replace(new RegExp(tag.name, 'g'), ``); }); }