ITADN

refactor: Use new URL for connection string parsing

#1127Pull Requestdenghongcai 创建于 2025-10-12
D
denghongcaicommented
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.
合并状态:未合并 1 条评论