fix: Normalize the tenant part of the URL. (#9577)

This PR normalises the tenant part of the URL. For example, the following URL

    https://jitsi-meet.example.com/something@example.com/something@example.com

is converted to

    https://jitsi-meet.example.com/somethingexample.com/somethingexample.com

whereas before it was converted to

    https://jitsi-meet.example.com/something@example.com/somethingexample.com

i.e. the tenant part was not normalised
This commit is contained in:
George Politis 2021-07-21 18:48:08 +01:00 committed by GitHub
parent 8c20dd8e47
commit 75edfc1fab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 23 deletions

View File

@ -45,17 +45,18 @@ const _URI_PATH_PATTERN = '([^?#]*)';
export const URI_PROTOCOL_PATTERN = '^([a-z][a-z0-9\\.\\+-]*:)'; export const URI_PROTOCOL_PATTERN = '^([a-z][a-z0-9\\.\\+-]*:)';
/** /**
* Excludes/removes certain characters from a specific room (name) which are * Excludes/removes certain characters from a specific path part which are
* incompatible with Jitsi Meet on the client and/or server sides. * incompatible with Jitsi Meet on the client and/or server sides. The main
* use case for this method is to clean up the room name and the tenant.
* *
* @param {?string} room - The room (name) to fix. * @param {?string} pathPart - The path part to fix.
* @private * @private
* @returns {?string} * @returns {?string}
*/ */
function _fixRoom(room: ?string) { function _fixPathPart(pathPart: ?string) {
return room return pathPart
? room.replace(new RegExp(_ROOM_EXCLUDE_PATTERN, 'g'), '') ? pathPart.replace(new RegExp(_ROOM_EXCLUDE_PATTERN, 'g'), '')
: room; : pathPart;
} }
/** /**
@ -335,6 +336,11 @@ export function parseURIString(uri: ?string) {
const obj = parseStandardURIString(_fixURIStringScheme(uri)); const obj = parseStandardURIString(_fixURIStringScheme(uri));
// XXX While the components/segments of pathname are URI encoded, Jitsi Meet
// on the client and/or server sides still don't support certain characters.
obj.pathname = obj.pathname.split('/').map(pathPart => _fixPathPart(pathPart))
.join('/');
// Add the properties that are specific to a Jitsi Meet resource (location) // Add the properties that are specific to a Jitsi Meet resource (location)
// such as contextRoot, room: // such as contextRoot, room:
@ -344,24 +350,9 @@ export function parseURIString(uri: ?string) {
// The room (name) is the last component/segment of pathname. // The room (name) is the last component/segment of pathname.
const { pathname } = obj; const { pathname } = obj;
// XXX While the components/segments of pathname are URI encoded, Jitsi Meet
// on the client and/or server sides still don't support certain characters.
const contextRootEndIndex = pathname.lastIndexOf('/'); const contextRootEndIndex = pathname.lastIndexOf('/');
let room = pathname.substring(contextRootEndIndex + 1) || undefined;
if (room) { obj.room = pathname.substring(contextRootEndIndex + 1) || undefined;
const fixedRoom = _fixRoom(room);
if (fixedRoom !== room) {
room = fixedRoom;
// XXX Drive fixedRoom into pathname (because room is derived from
// pathname).
obj.pathname
= pathname.substring(0, contextRootEndIndex + 1) + (room || '');
}
}
obj.room = room;
if (contextRootEndIndex > 1) { if (contextRootEndIndex > 1) {
// The part of the pathname from the beginning to the room name is the tenant. // The part of the pathname from the beginning to the room name is the tenant.