Parcourir la source

feat: safe decodeURIComponent

master
Bettenbuk Zoltan il y a 6 ans
Parent
révision
8bd0da886e

+ 2
- 1
react/features/base/conference/functions.js Voir le fichier

@@ -11,6 +11,7 @@ import {
11 11
     participantLeft
12 12
 } from '../participants';
13 13
 import { toState } from '../redux';
14
+import { safeDecodeURIComponent } from '../util';
14 15
 
15 16
 import {
16 17
     AVATAR_ID_COMMAND,
@@ -163,7 +164,7 @@ export function getConferenceName(stateful: Function | Object): string {
163 164
         || subject
164 165
         || callDisplayName
165 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 Voir le fichier

@@ -373,6 +373,23 @@ function _standardURIToString(thiz: ?Object) {
373 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 394
  * Attempts to return a {@code String} representation of a specific
378 395
  * {@code Object} which is supposed to represent a URL. Obviously, if a

+ 2
- 2
react/features/recent-list/functions.native.js Voir le fichier

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

Chargement…
Annuler
Enregistrer