Commit 3c3b168
committed
refactor: Use new URL for connection string parsing
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 parent 32feb25 commit 3c3b168
1 file changed
+35
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
462 | 462 | | |
463 | 463 | | |
464 | 464 | | |
465 | | - | |
466 | | - | |
467 | | - | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
468 | 468 | | |
469 | 469 | | |
470 | 470 | | |
| |||
533 | 533 | | |
534 | 534 | | |
535 | 535 | | |
536 | | - | |
537 | | - | |
| 536 | + | |
| 537 | + | |
538 | 538 | | |
539 | 539 | | |
540 | | - | |
541 | | - | |
542 | | - | |
| 540 | + | |
543 | 541 | | |
544 | | - | |
| 542 | + | |
545 | 543 | | |
546 | 544 | | |
547 | 545 | | |
548 | | - | |
549 | | - | |
550 | | - | |
551 | | - | |
552 | | - | |
553 | | - | |
554 | | - | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
555 | 553 | | |
556 | | - | |
| 554 | + | |
557 | 555 | | |
558 | 556 | | |
559 | 557 | | |
| |||
564 | 562 | | |
565 | 563 | | |
566 | 564 | | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
0 commit comments