Skip to content

Support bracketed IPv6 hosts in connection strings - #1233

Open
Nitjsefnie wants to merge 1 commit into
porsager:masterfrom
Nitjsefnie-OSC:fix-ipv6-host
Open

Nitjsefnie wants to merge 1 commit into
porsager:masterfrom
Nitjsefnie-OSC:fix-ipv6-host

Conversation

@Nitjsefnie

Copy link
Copy Markdown

Summary

Connection strings with a bracketed IPv6 host (postgres://u:p@[::1]:5432/db) resolved to host [ and could not connect; each host entry is now parsed with bracket awareness, and a bare IPv6 host option or PGHOST value is kept whole.

Related Issues and Pull Requests

Fixes #1232

Relates to #663

Relates to #1127

Changes

  • src/index.js: parseOptions maps each comma-separated host entry through a small parseHost helper. [addr] / [addr]:port yields addr and that port (or the default), an unbracketed value with more than one : (a bare IPv6 address such as ::1) is taken whole, and everything else is split at : exactly as before, so hostname, IPv4, host:port, multi-host and socket-path behaviour is unchanged.
  • tests/index.js: five cases next to Multiple hosts — bracketed IPv6 with and without a port, two bracketed hosts, a bare ::1 host option, and the existing h1:1,h2:2 form.
  • cjs/, deno/, cf/: the matching npm run build output for those two files only.
  • Compared with the open pull requests: add support for ipv6 addr postgres://user:password@[2a02:c206:2140:4… #663 fixes the bracketed URL case but throws ERR_INVALID_URL for a bare ::1 host option and has no tests; refactor: Use new URL for connection string parsing #1127 turns a multi-host entry [::1]:5432 into host ::1]:543.

Testing

  • The new tests failed on master ('[["::1"],[5432]]' != '[["["],[5432]]') and pass with the change.
  • Full node tests/index.js and node cjs/tests/index.js passed against a local PostgreSQL with the second server on port 5433, as in CI. Two existing timing-sensitive tests (reserve connection, listen and notify with weird name) failed on earlier runs and passed on re-run; they do not touch host parsing.
  • npm run lint passed.
  • The Deno tests were not run (no Deno CLI available); the Deno files are the build output.
  • The same change has run as a local patch on 3.4.9 in Nitjsefnie/Overflow, whose suite includes a test that connects to a server listening only on ::1.

Footer

Generated by Claude Opus 5.5 (brief, review), GPT-6 Sol (implementation, review)

Co-Authored-By: GPT-6 Sol <noreply@openai.com>
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.

Bracketed IPv6 host in a connection string resolves to "[" and cannot connect

1 participant