Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

feat: safe decodeURIComponent

Bettenbuk Zoltan8bd0da886ebd
diff --git a/react/features/base/conference/functions.js b/react/features/base/conference/functions.js
index 10a461de54..b10ab4b622 100644
--- a/react/features/base/conference/functions.js
+++ b/react/features/base/conference/functions.js
@@ -11,6 +11,7 @@ import {
participantLeft
} from '../participants';
import { toState } from '../redux';
+import { safeDecodeURIComponent } from '../util';
import {
AVATAR_ID_COMMAND,
@@ -163,7 +164,7 @@ export function getConferenceName(stateful: Function | Object): string {
|| subject
|| callDisplayName
|| (callee && callee.name)
- || _.startCase(decodeURIComponent(room));
+ || _.startCase(safeDecodeURIComponent(room));
}
/**
diff --git a/react/features/base/util/uri.js b/react/features/base/util/uri.js
index b7459a7273..6917d1a944 100644
--- a/react/features/base/util/uri.js
+++ b/react/features/base/util/uri.js
@@ -373,6 +373,23 @@ function _standardURIToString(thiz: ?Object) {
return str;
}
+/**
+ * Sometimes we receive strings that we don't know if already percent-encoded, or not, due to the
+ * various sources we get URLs or room names. This function encapsulates the decoding in a safe way.
+ *
+ * @param {string} text - The text to decode.
+ * @returns {string}
+ */
+export function safeDecodeURIComponent(text: string) {
+ try {
+ return decodeURIComponent(text);
+ } catch (e) {
+ // The text wasn't encoded.
+ }
+
+ return text;
+}
+
/**
* Attempts to return a {@code String} representation of a specific
* {@code Object} which is supposed to represent a URL. Obviously, if a
diff --git a/react/features/recent-list/functions.native.js b/react/features/recent-list/functions.native.js
index d5a98a4cea..2ed1aa55cf 100644
--- a/react/features/recent-list/functions.native.js
+++ b/react/features/recent-list/functions.native.js
@@ -3,7 +3,7 @@ import {
getLocalizedDurationFormatter
} from '../base/i18n';
import { NavigateSectionList } from '../base/react';
-import { parseURIString } from '../base/util';
+import { parseURIString, safeDecodeURIComponent } from '../base/util';
/**
* Creates a displayable list item of a recent list entry.
@@ -31,7 +31,7 @@ function toDisplayableItem(item, defaultServerURL, t) {
_toDurationString(item.duration),
serverName
],
- title: decodeURIComponent(location.room),
+ title: safeDecodeURIComponent(location.room),
url: item.conference
};
}