Преглед на файлове

feat: safe decodeURIComponent

master
Bettenbuk Zoltan преди 6 години
родител
ревизия
8bd0da886e
променени са 3 файла, в които са добавени 21 реда и са изтрити 3 реда
  1. 2
    1
      react/features/base/conference/functions.js
  2. 17
    0
      react/features/base/util/uri.js
  3. 2
    2
      react/features/recent-list/functions.native.js

+ 2
- 1
react/features/base/conference/functions.js Целия файл

11
     participantLeft
11
     participantLeft
12
 } from '../participants';
12
 } from '../participants';
13
 import { toState } from '../redux';
13
 import { toState } from '../redux';
14
+import { safeDecodeURIComponent } from '../util';
14
 
15
 
15
 import {
16
 import {
16
     AVATAR_ID_COMMAND,
17
     AVATAR_ID_COMMAND,
163
         || subject
164
         || subject
164
         || callDisplayName
165
         || callDisplayName
165
         || (callee && callee.name)
166
         || (callee && callee.name)
166
-        || _.startCase(decodeURIComponent(room));
167
+        || _.startCase(safeDecodeURIComponent(room));
167
 }
168
 }
168
 
169
 
169
 /**
170
 /**

+ 17
- 0
react/features/base/util/uri.js Целия файл

373
     return str;
373
     return str;
374
 }
374
 }
375
 
375
 
376
+/**
377
+ * Sometimes we receive strings that we don't know if already percent-encoded, or not, due to the
378
+ * various sources we get URLs or room names. This function encapsulates the decoding in a safe way.
379
+ *
380
+ * @param {string} text - The text to decode.
381
+ * @returns {string}
382
+ */
383
+export function safeDecodeURIComponent(text: string) {
384
+    try {
385
+        return decodeURIComponent(text);
386
+    } catch (e) {
387
+        // The text wasn't encoded.
388
+    }
389
+
390
+    return text;
391
+}
392
+
376
 /**
393
 /**
377
  * Attempts to return a {@code String} representation of a specific
394
  * Attempts to return a {@code String} representation of a specific
378
  * {@code Object} which is supposed to represent a URL. Obviously, if a
395
  * {@code Object} which is supposed to represent a URL. Obviously, if a

+ 2
- 2
react/features/recent-list/functions.native.js Целия файл

3
     getLocalizedDurationFormatter
3
     getLocalizedDurationFormatter
4
 } from '../base/i18n';
4
 } from '../base/i18n';
5
 import { NavigateSectionList } from '../base/react';
5
 import { NavigateSectionList } from '../base/react';
6
-import { parseURIString } from '../base/util';
6
+import { parseURIString, safeDecodeURIComponent } from '../base/util';
7
 
7
 
8
 /**
8
 /**
9
  * Creates a displayable list item of a recent list entry.
9
  * Creates a displayable list item of a recent list entry.
31
             _toDurationString(item.duration),
31
             _toDurationString(item.duration),
32
             serverName
32
             serverName
33
         ],
33
         ],
34
-        title: decodeURIComponent(location.room),
34
+        title: safeDecodeURIComponent(location.room),
35
         url: item.conference
35
         url: item.conference
36
     };
36
     };
37
 }
37
 }

Loading…
Отказ
Запис