Skip to content

net.isIP fails to detect different formats #40966

@abaetu

Description

@abaetu

Version

v16.13.0

Platform

Darwin xxx.local 20.6.0 Darwin Kernel Version 20.6.0: Tue Oct 12 18:33:38 PDT 2021; root:xnu-7195.141.8~1/RELEASE_ARM64_T8101 arm64

Subsystem

net

What steps will reproduce the bug?

net.isIP("192.0250.1.1")
0
net.isIP("030052000401")
0
net.isIP("0xc0.168.1.1")
0
net.isIP("3232235777")
0
net.isIP("127.42.258")
0
net.isIP("127.66051")
0
net.isIP("10.1.1.0xff")

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior?

4

What do you see instead?

0

Additional information

I was looking for a way of checking if a hostname in an URL is an IP (v4 or V6) and found the "net" nodejs module. But it is unable to detect different formats. Open a browser and put any of the strings in the description, with a http:// in front, and see that it is correctly converted to the canonical form.
Also would be great if you could add the conversion to canonical form for both ipv4 and ipv6 (https://datatracker.ietf.org/doc/html/rfc5952#section-4)

Metadata

Metadata

Assignees

No one assigned

    Labels

    netIssues and PRs related to the net subsystem.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions