Commit ab7fa589 authored by Harrison Healey's avatar Harrison Healey Committed by Saturnino Abril

MM-11016 Prevent error when failing to parse websocket origin (#551)

parent 8c9603c3
......@@ -70,17 +70,25 @@ class WebSocketClient {
this.connectingCallback(dispatch, getState);
}
const regex = /^(?:https?|wss?):\/\/[^/]*/;
const regex = /^(?:https?|wss?):(?:\/\/)?[^/]*/;
const captured = (regex).exec(connectionUrl);
let origin = captured[0];
if (platform === 'android') {
// this is done cause for android having the port 80 or 443 will fail the connection
// the websocket will append them
const split = origin.split(':');
const port = split[2];
if (port === '80' || port === '443') {
origin = `${split[0]}:${split[1]}`;
let origin;
if (captured) {
origin = captured[0];
if (platform === 'android') {
// this is done cause for android having the port 80 or 443 will fail the connection
// the websocket will append them
const split = origin.split(':');
const port = split[2];
if (port === '80' || port === '443') {
origin = `${split[0]}:${split[1]}`;
}
}
} else {
// If we're unable to set the origin header, the websocket won't connect, but the URL is likely malformed anyway
console.warn('websocket failed to parse origin from ' + connectionUrl); // eslint-disable-line no-console
}
this.conn = new Socket(connectionUrl, [], {headers: {origin}, ...(additionalOptions || {})});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment