浏览代码

fix(gifs): trim the message before extracting the URL.

factor2
Hristo Terezov 9 个月前
父节点
当前提交
32f9f8ba92

+ 2
- 3
react/features/base/react/components/web/Message.tsx 查看文件

@@ -4,8 +4,7 @@ import { connect } from 'react-redux';
4 4
 
5 5
 import { IReduxState } from '../../../../app/types';
6 6
 import GifMessage from '../../../../chat/components/web/GifMessage';
7
-import { GIF_PREFIX } from '../../../../gifs/constants';
8
-import { isGifEnabled, isGifMessage } from '../../../../gifs/functions.web';
7
+import { extractGifURL, isGifEnabled, isGifMessage } from '../../../../gifs/functions.web';
9 8
 
10 9
 import Linkify from './Linkify';
11 10
 
@@ -55,7 +54,7 @@ class Message extends Component<IProps> {
55 54
 
56 55
         // check if the message is a GIF
57 56
         if (gifEnabled && isGifMessage(text)) {
58
-            const url = text.substring(GIF_PREFIX.length, text.length - 1);
57
+            const url = extractGifURL(text);
59 58
 
60 59
             content.push(<GifMessage
61 60
                 key = { url }

+ 2
- 2
react/features/chat/components/native/GifMessage.tsx 查看文件

@@ -1,7 +1,7 @@
1 1
 import React from 'react';
2 2
 import { Image, ImageStyle, View } from 'react-native';
3 3
 
4
-import { GIF_PREFIX } from '../../../gifs/constants';
4
+import { extractGifURL } from '../../../gifs/function.any';
5 5
 
6 6
 import styles from './styles';
7 7
 
@@ -14,7 +14,7 @@ interface IProps {
14 14
 }
15 15
 
16 16
 const GifMessage = ({ message }: IProps) => {
17
-    const url = message.substring(GIF_PREFIX.length, message.length - 1);
17
+    const url = extractGifURL(message);
18 18
 
19 19
     return (<View
20 20
         id = 'gif-message'

+ 2
- 3
react/features/chat/middleware.ts 查看文件

@@ -24,8 +24,7 @@ import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
24 24
 import StateListenerRegistry from '../base/redux/StateListenerRegistry';
25 25
 import { playSound, registerSound, unregisterSound } from '../base/sounds/actions';
26 26
 import { addGif } from '../gifs/actions';
27
-import { GIF_PREFIX } from '../gifs/constants';
28
-import { getGifDisplayMode, isGifEnabled, isGifMessage } from '../gifs/function.any';
27
+import { extractGifURL, getGifDisplayMode, isGifEnabled, isGifMessage } from '../gifs/function.any';
29 28
 import { showMessageNotification } from '../notifications/actions';
30 29
 import { NOTIFICATION_TIMEOUT_TYPE } from '../notifications/constants';
31 30
 import { resetNbUnreadPollsMessages } from '../polls/actions';
@@ -351,7 +350,7 @@ function _onConferenceMessageReceived(store: IStore,
351 350
  * @returns {void}
352 351
  */
353 352
 function _handleGifMessageReceived(store: IStore, participantId: string, message: string) {
354
-    const url = message.substring(GIF_PREFIX.length, message.length - 1);
353
+    const url = extractGifURL(message);
355 354
 
356 355
     store.dispatch(addGif(participantId, url));
357 356
 }

+ 22
- 4
react/features/gifs/function.any.ts 查看文件

@@ -71,11 +71,29 @@ export function isGifUrlAllowed(url: string) {
71 71
  * @param {string} message - Message to check.
72 72
  * @returns {boolean}
73 73
  */
74
-export function isGifMessage(message: string) {
75
-    const url = message.substring(GIF_PREFIX.length, message.length - 1);
74
+export function isGifMessage(message = '') {
75
+    const trimmedMessage = message.trim();
76
+
77
+    if (!trimmedMessage.toLowerCase().startsWith(GIF_PREFIX)) {
78
+        return false;
79
+    }
80
+
81
+    const url = extractGifURL(trimmedMessage);
82
+
83
+    return isGifUrlAllowed(url);
84
+}
85
+
86
+/**
87
+ * Extracts the URL from a gif message.
88
+ *
89
+ * @param {string} message - The message.
90
+ * @returns {string} - The URL.
91
+ */
92
+export function extractGifURL(message = '') {
93
+    const trimmedMessage = message.trim();
94
+
95
+    return trimmedMessage.substring(GIF_PREFIX.length, trimmedMessage.length - 1);
76 96
 
77
-    return message.trim().toLowerCase()
78
-        .startsWith(GIF_PREFIX) && isGifUrlAllowed(url);
79 97
 }
80 98
 
81 99
 /**

正在加载...
取消
保存