Skip to content

Conversation

denghongcai
Copy link

This commit refactors the connection URL parsing logic in src/index.js to use the new URL() constructor. This change provides a more robust and standardized way to parse connection strings, addressing several limitations of the previous implementation:

  • IPv6 Support: The new parsing logic correctly handles IPv6 addresses in connection strings.
  • Encoded Password Handling: Usernames and passwords with special characters that have been URL-encoded are now correctly decoded.

To achieve this, the parseUrl function was rewritten to replace the postgres:// or postgresql:// protocol with http:// before passing the string to the URL constructor. This allows the use of the standard URL parsing mechanism for a custom protocol.

Additionally, two new helper functions, parseHost and parsePort, have been introduced to correctly extract host and port information from various formats, including single-host, multi-host, and IPv6 addresses.

This commit refactors the connection URL parsing logic in `src/index.js` to use the `new URL()` constructor. This change provides a more robust and standardized way to parse connection strings, addressing several limitations of the previous implementation:

- **IPv6 Support:** The new parsing logic correctly handles IPv6 addresses in connection strings.
- **Encoded Password Handling:** Usernames and passwords with special characters that have been URL-encoded are now correctly decoded.

To achieve this, the `parseUrl` function was rewritten to replace the `postgres://` or `postgresql://` protocol with `http://` before passing the string to the `URL` constructor. This allows the use of the standard URL parsing mechanism for a custom protocol.

Additionally, two new helper functions, `parseHost` and `parsePort`, have been introduced to correctly extract host and port information from various formats, including single-host, multi-host, and IPv6 addresses.
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.

1 participant