net: fix SocketAddress.parse default port handling#62912
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes net.SocketAddress.parse() so it correctly preserves explicit default ports (notably :80) that are otherwise dropped by URL.parse() when using an http:// base, aligning behavior with expectations and documentation.
Changes:
- Update
SocketAddress.parse()to derive the port from the raw input string rather thanurl.port. - Simplify the parse return path to a single
SocketAddressconstruction for both IPv4 and IPv6. - Add regression tests covering IPv4/IPv6 with explicit ports
80and443.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
lib/internal/socketaddress.js |
Fixes default-port handling by parsing the port from the raw input instead of URLParse(...).port. |
test/parallel/test-socketaddress.js |
Adds regression coverage ensuring explicit :80/:443 are preserved for both IPv4 and IPv6. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #62912 +/- ##
==========================================
+ Coverage 89.67% 89.68% +0.01%
==========================================
Files 712 712
Lines 221251 221260 +9
Branches 42391 42393 +2
==========================================
+ Hits 198405 198438 +33
+ Misses 14669 14629 -40
- Partials 8177 8193 +16
🚀 New features to boost your workflow:
|
87d545a to
7563aff
Compare
|
I noticed one extra behavior change from parsing the port with For example, current SocketAddress.parse('user:80@5.6.7.8')
SocketAddress.parse('user:81@5.6.7.8')With this patch they become ports An alternative is to keep using the HTTP URL parse for the address and existing non-default ports, and only when URLParse(`socket://${input}`).portThat preserves the existing URL host parsing while recovering explicit host ports like |
Great finding and solution, thank you @cookesan |
Actually, I did some benchmarks and noticed the double |
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
5c4f673 to
8435ef4
Compare
Fixes #62906