Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1569
Problem
When connecting to a WebSocket URL with an IPv6 address such as
ws://[::1]:8883,url.parse()insrc/lib/connect/index.tsstrips the square brackets from the hostname (hostname: '::1').Downstream in
ws.ts(as well asali.tsandwx.ts),buildUrl()reconstructed the URL using${opts.protocol}://${opts.hostname}:${opts.port}${opts.path}, yieldingws://::1:8883/. Because RFC 3986 and WHATWG URL standards require IPv6 hostnames in URLs to be enclosed in square brackets, passing this string tonew WebSocket()ornew URL()immediately threw:This also affected connections using options objects with IPv6 addresses (e.g.
{ host: '::1', port: 8883, protocol: 'ws' }).Solution
formatUrlHosthelper function insrc/lib/shared.tsthat ensures unbracketed IPv6 hostnames (containing:without leading/trailing brackets) are enclosed in[...]when constructing URL strings.buildUrlinsrc/lib/connect/ws.ts,src/lib/connect/ali.ts, andsrc/lib/connect/wx.tsto useformatUrlHost.net.connect,tls.connect) where unbracketed IPs are expected.Testing
test/node/mqtt.tsvalidating:ws://[::1]:8883).{ host: '::1', port: 8883, protocol: 'ws' }).npm run buildandeslintpass cleanly.