Skip to content

feat: enhance host and port parsing to support IPv6 addresses#781

Open
podrivo wants to merge 1 commit into
gamedig:masterfrom
podrivo:fix-ipv6-address
Open

feat: enhance host and port parsing to support IPv6 addresses#781
podrivo wants to merge 1 commit into
gamedig:masterfrom
podrivo:fix-ipv6-address

Conversation

@podrivo

@podrivo podrivo commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Closes #769

Problem

The CLI split the target on every colon (target.split(':')), so IPv6 addresses broke — the first internal colon was treated as the host/port separator, even in bracketed form ([2001:db8::1]:27015):

$ gamedig --type minecraft [2409:8a55:...:3ed1]:25565 --debug
  host: '[2409'
Q#0 Query failed with error Error: Invalid domain

Fix

Reworked host/port parsing in bin/gamedig.js. Besides the bracketed form, colon count disambiguates: exactly one colon means host:port; zero or 2+ means the whole string is the host (hostnames, IPv4, unbracketed IPv6).

if (argv._.length >= 1) {
  const target = String(argv._[0])
  const bracketed = target.match(/^\[(.+)\](?::(.+))?$/)
  if (bracketed) {
    options.host = bracketed[1]
    if (bracketed[2]) options.port = bracketed[2]
  } else if (target.split(':').length === 2) {
    [options.host, options.port] = target.split(':')
  } else {
    options.host = target
  }
}

No downstream changes needed: DnsResolver.resolve() already short-circuits valid IPs via isIP(host).

Compatibility

Hostnames, IPv4, and host:port parse identically to before — only the broken IPv6 cases change. String(...) guards against Minimist coercing a numeric-only host to a number.

Testing

  • Verified the issue repro now parses correctly and reaches a TCP connection attempt.
  • Diffed old vs. new parsing across all input types — identical for valid existing inputs.
  • npm run lint:check passes.

@podrivo podrivo changed the title fix: enhance host and port parsing to support IPv6 addresses feat: enhance host and port parsing to support IPv6 addresses Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: CLI fails to parse IPv6 addresses; treats colons as port delimiters

1 participant