From 2ec81605127cec82fae5064dd59da2798a628e02 Mon Sep 17 00:00:00 2001 From: Ilkka Oksanen Date: Fri, 12 Feb 2021 17:24:53 +0200 Subject: [PATCH] fix: remove double brackets from the ws url when using raw IPv6 address (#2951) --- client-src/default/utils/createSocketUrl.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/client-src/default/utils/createSocketUrl.js b/client-src/default/utils/createSocketUrl.js index a14ec5965a..50ffd51730 100644 --- a/client-src/default/utils/createSocketUrl.js +++ b/client-src/default/utils/createSocketUrl.js @@ -72,7 +72,7 @@ function getSocketUrl(urlParts, loc) { // all of these sock url params are optionally passed in through // resourceQuery, so we need to fall back to the default if // they are not provided - const host = query.host || hostname; + let host = query.host || hostname; const path = query.path || '/ws'; let portOption = query.port || port; @@ -80,6 +80,13 @@ function getSocketUrl(urlParts, loc) { portOption = loc.port; } + // In case the host is a raw IPv6 address, it can be enclosed in + // the brackets as the brackets are needed in the final URL string. + // Need to remove those as url.format blindly adds its own set of brackets + // if the host string contains colons. That would lead to non-working + // double brackets (e.g. [[::]]) host + host = typeof host === 'string' ? host.replace(/^\[(.*)\]$/, '$1') : host; + return url.format({ protocol, auth,