feat: safe decodeURIComponent

This commit is contained in:
Bettenbuk Zoltan 2019-11-15 14:09:15 +01:00 committed by Zoltan Bettenbuk
parent 1fd326f980
commit 8bd0da886e
3 changed files with 21 additions and 3 deletions

View File

@ -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));
}
/**

View File

@ -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

View File

@ -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
};
}