From b82b676fdb9e27ecd4e75dfbab84537c68234997 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Thu, 22 Jun 2023 11:08:50 +0200 Subject: [PATCH] fix(xen-api/transports/json-rpc): fix IPv6 address support Introduced by ab96c549a --- CHANGELOG.unreleased.md | 4 ++++ packages/xen-api/_parseUrl.spec.js | 2 +- packages/xen-api/src/_parseUrl.js | 5 ++--- packages/xen-api/src/transports/xml-rpc.js | 4 +++- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 77ab5de5a..51bf89ce9 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -11,6 +11,8 @@ > Users must be able to say: “I had this issue, happy to know it's fixed” +- [Settings/Servers] Fix connecting using an explicit IPv6 address + ### Packages to release > When modifying a package, add it here with its release type. @@ -27,4 +29,6 @@ +- xen-api patch + diff --git a/packages/xen-api/_parseUrl.spec.js b/packages/xen-api/_parseUrl.spec.js index 630385219..f44effd55 100644 --- a/packages/xen-api/_parseUrl.spec.js +++ b/packages/xen-api/_parseUrl.spec.js @@ -11,7 +11,7 @@ const data = { protocol: 'https:', }, '[::1]': { - hostname: '::1', + hostname: '[::1]', pathname: '/', protocol: 'https:', }, diff --git a/packages/xen-api/src/_parseUrl.js b/packages/xen-api/src/_parseUrl.js index 1a2e03932..066fb6c4f 100644 --- a/packages/xen-api/src/_parseUrl.js +++ b/packages/xen-api/src/_parseUrl.js @@ -1,4 +1,4 @@ -const URL_RE = /^(?:(https?:)\/*)?(?:(([^:]*)(?::([^@]*))?)@)?(?:\[([^\]]+)\]|([^:/]+))(?::([0-9]+))?(\/[^?#]*)?$/ +const URL_RE = /^(?:(https?:)\/*)?(?:(([^:]*)(?::([^@]*))?)@)?(\[[^\]]+\]|[^:/]+)(?::([0-9]+))?(\/[^?#]*)?$/ export default url => { const matches = URL_RE.exec(url) @@ -6,8 +6,7 @@ export default url => { throw new Error('invalid URL: ' + url) } - const [, protocol = 'https:', auth, username = '', password = '', ipv6, hostname = ipv6, port, pathname = '/'] = - matches + const [, protocol = 'https:', auth, username = '', password = '', hostname, port, pathname = '/'] = matches const parsedUrl = { protocol, hostname, diff --git a/packages/xen-api/src/transports/xml-rpc.js b/packages/xen-api/src/transports/xml-rpc.js index 5117c1a80..5b8794d1c 100644 --- a/packages/xen-api/src/transports/xml-rpc.js +++ b/packages/xen-api/src/transports/xml-rpc.js @@ -30,12 +30,14 @@ const parseResult = result => { return result.Value } +const removeBrackets = hostname => (hostname[0] === '[' ? hostname.slice(1, -1) : hostname) + export default ({ secureOptions, url: { hostname, pathname, port, protocol }, agent }) => { const secure = protocol === 'https:' const client = (secure ? createSecureClient : createClient)({ ...(secure ? secureOptions : undefined), agent, - host: hostname, + host: removeBrackets(hostname), pathname, port, })