Page MenuHomePhabricator

D6398.id21404.diff
No OneTemporary

D6398.id21404.diff

diff --git a/keyserver/src/responders/message-responders.js b/keyserver/src/responders/message-responders.js
--- a/keyserver/src/responders/message-responders.js
+++ b/keyserver/src/responders/message-responders.js
@@ -3,6 +3,7 @@
import invariant from 'invariant';
import t from 'tcomb';
+import { onlyOneEmojiRegex } from 'lib/shared/emojis';
import { createMediaMessageData, trimMessage } from 'lib/shared/message-utils';
import { relationshipBlockedInEitherDirection } from 'lib/shared/relationship-utils';
import type { Media } from 'lib/types/media-types.js';
@@ -20,11 +21,7 @@
import type { TextMessageData } from 'lib/types/messages/text';
import { threadPermissions } from 'lib/types/thread-types';
import { ServerError } from 'lib/utils/errors';
-import {
- tString,
- tShape,
- tMediaMessageMedia,
-} from 'lib/utils/validation-utils';
+import { tRegex, tShape, tMediaMessageMedia } from 'lib/utils/validation-utils';
import createMessages from '../creators/message-creator';
import { SQL } from '../database/database';
@@ -194,7 +191,7 @@
threadID: t.String,
localID: t.maybe(t.String),
targetMessageID: t.String,
- reaction: tString('πŸ‘'),
+ reaction: tRegex(onlyOneEmojiRegex),
action: t.enums.of(['add_reaction', 'remove_reaction']),
});
async function reactionMessageCreationResponder(
diff --git a/lib/shared/emojis.js b/lib/shared/emojis.js
--- a/lib/shared/emojis.js
+++ b/lib/shared/emojis.js
@@ -9,6 +9,8 @@
'could not extract innerEmojiRegex from emoji-regex.js',
);
const innerEmojiRegexString = emojiRegexMatches[1];
+
const onlyEmojiRegex: RegExp = new RegExp(`^(${innerEmojiRegexString})+$`);
+const onlyOneEmojiRegex: RegExp = new RegExp(`^(${innerEmojiRegexString})$`);
-export { onlyEmojiRegex };
+export { onlyEmojiRegex, onlyOneEmojiRegex };
diff --git a/lib/shared/emojis.test.js b/lib/shared/emojis.test.js
new file mode 100644
--- /dev/null
+++ b/lib/shared/emojis.test.js
@@ -0,0 +1,25 @@
+// @flow
+
+import { onlyOneEmojiRegex } from './emojis';
+
+describe('onlyOneEmojiRegex', () => {
+ it('should match for (πŸ‘)', () => {
+ expect('πŸ‘').toMatch(onlyOneEmojiRegex);
+ });
+
+ it('should match for (🫑)', () => {
+ expect('🫑').toMatch(onlyOneEmojiRegex);
+ });
+
+ it('should match for (🦢🏾)', () => {
+ expect('🦢🏾').toMatch(onlyOneEmojiRegex);
+ });
+
+ it('should not match for (πŸ¦ΆπŸΎπŸ™)', () => {
+ expect('πŸ¦ΆπŸΎπŸ™').not.toMatch(onlyOneEmojiRegex);
+ });
+
+ it('should not match for (that is πŸ”₯)', () => {
+ expect('that is πŸ”₯').not.toMatch(onlyOneEmojiRegex);
+ });
+});

File Metadata

Mime Type
text/plain
Expires
Thu, Dec 19, 7:17 PM (21 h, 35 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2678258
Default Alt Text
D6398.id21404.diff (2 KB)

Event Timeline