Skip to content

Commit

Permalink
fix: utf-8 room name case sensitivity
Browse files Browse the repository at this point in the history
  • Loading branch information
zbettenbuk committed Oct 8, 2019
1 parent 34a7104 commit 13d78d6
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 16 deletions.
3 changes: 2 additions & 1 deletion react/features/app/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { connect, disconnect, setLocationURL } from '../base/connection';
import { loadConfig } from '../base/lib-jitsi-meet';
import { createDesiredLocalTracks } from '../base/tracks';
import {
getBackendSafeRoomName,
getLocationContextRoot,
parseURIString,
toURLString
Expand Down Expand Up @@ -85,7 +86,7 @@ export function appNavigate(uri: ?string) {
let url = `${baseURL}config.js`;

// XXX In order to support multiple shards, tell the room to the deployment.
room && (url += `?room=${room.toLowerCase()}`);
room && (url += `?room=${getBackendSafeRoomName(room)}`);

let config;

Expand Down
8 changes: 5 additions & 3 deletions react/features/base/conference/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import {
participantUpdated
} from '../participants';
import { getLocalTracks, trackAdded, trackRemoved } from '../tracks';
import { getJitsiMeetGlobalNS } from '../util';
import {
getBackendSafeRoomName,
getJitsiMeetGlobalNS
} from '../util';

import {
AUTH_STATUS_CHANGED,
Expand Down Expand Up @@ -388,8 +391,7 @@ export function createConference() {
const conference
= connection.initJitsiConference(

// XXX Lib-jitsi-meet does not accept uppercase letters.
room.toLowerCase(), {
getBackendSafeRoomName(room), {
...state['features/base/config'],
applicationName: getName(),
getWiFiStatsMethod: getJitsiMeetGlobalNS().getWiFiStats,
Expand Down
8 changes: 4 additions & 4 deletions react/features/base/config/getRoomName.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* @flow */

import { getBackendSafeRoomName } from '../util';

declare var config: Object;

/**
Expand All @@ -20,10 +22,8 @@ export default function getRoomName(): ?string {
// URL maps to the room (name). It currently assumes a deployment in
// which the last non-directory component of the path (name) is the
// room.
roomName
= path.substring(path.lastIndexOf('/') + 1).toLowerCase()
|| undefined;
roomName = path.substring(path.lastIndexOf('/') + 1) || undefined;
}

return roomName;
return getBackendSafeRoomName(roomName);
}
10 changes: 5 additions & 5 deletions react/features/base/connection/actions.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import {
getCurrentConference
} from '../conference';
import JitsiMeetJS, { JitsiConnectionEvents } from '../lib-jitsi-meet';
import { parseURIString } from '../util';
import {
getBackendSafeRoomName,
parseURIString
} from '../util';

import {
CONNECTION_DISCONNECTED,
Expand Down Expand Up @@ -307,10 +310,7 @@ function _constructOptions(state) {
// Append room to the URL's search.
const { room } = state['features/base/conference'];

// XXX The Jitsi Meet deployments require the room argument to be in
// lower case at the time of this writing but, unfortunately, they do
// not ignore case themselves.
room && (bosh += `?room=${room.toLowerCase()}`);
room && (bosh += `?room=${getBackendSafeRoomName(room)}`);

options.bosh = bosh;
}
Expand Down
4 changes: 2 additions & 2 deletions react/features/base/connection/actions.web.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ declare var APP: Object;
declare var config: Object;

import { configureInitialDevices } from '../devices';
import { getBackendSafeRoomName } from '../util';

export {
connectionEstablished,
Expand All @@ -21,8 +22,7 @@ import logger from './logger';
*/
export function connect() {
return (dispatch: Dispatch<any>, getState: Function) => {
// XXX Lib-jitsi-meet does not accept uppercase letters.
const room = getState()['features/base/conference'].room.toLowerCase();
const room = getBackendSafeRoomName(getState()['features/base/conference'].room);

// XXX For web based version we use conference initialization logic
// from the old app (at the moment of writing).
Expand Down
41 changes: 41 additions & 0 deletions react/features/base/util/uri.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,47 @@ function _fixURIStringScheme(uri: string) {
return uri;
}

/**
* Converts a room name to a backend-safe format. Properly lowercased and url encoded.
*
* @param {string?} room - The room name to convert.
* @returns {string?}
*/
export function getBackendSafeRoomName(room: ?string): ?string {
if (!room) {
return room;
}

/* eslint-disable no-param-reassign */
try {
// We do not know if we get an already encoded string at this point
// as different platforms do it differently, but we need a decoded one
// for sure. However since decoding a non-encoded string is a noop, we're safe
// doing it here.
room = decodeURIComponent(room);
} catch (e) {
// This can happen though if we get an unencoded string and it contains
// some characters that look like an encoded entity, but it's not.
// But in this case we're fine goin on...
}

// Normalize the character set
room = room.normalize('NFKC');

// Only decoded and normalized strings can be lowercased properly.
room = room.toLowerCase();

// But we still need to (re)encode it.
room = encodeURIComponent(room);
/* eslint-enable no-param-reassign */

// Unfortunately we still need to lowercase it, because encoding a string will
// add some uppercase characters, but some backend services
// expect it to be full lowercase. However lowercasing an encoded string
// doesn't change the string value.
return room.toLowerCase();
}

/**
* Gets the (Web application) context root defined by a specific location (URI).
*
Expand Down
2 changes: 1 addition & 1 deletion react/features/welcome/components/AbstractWelcomePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export class AbstractWelcomePage extends Component<Props, *> {
const onAppNavigateSettled
= () => this._mounted && this.setState({ joining: false });

this.props.dispatch(appNavigate(encodeURI(room)))
this.props.dispatch(appNavigate(room))
.then(onAppNavigateSettled, onAppNavigateSettled);
}
}
Expand Down

0 comments on commit 13d78d6

Please sign in to comment.