Skip to content

Fix(IPRange): Allow contains() to accept single IP addresses#104

Merged
dadepo merged 4 commits intomasterfrom
fix-contains-ip-type
Jun 8, 2025
Merged

Fix(IPRange): Allow contains() to accept single IP addresses#104
dadepo merged 4 commits intomasterfrom
fix-contains-ip-type

Conversation

@dadepo
Copy link
Member

@dadepo dadepo commented Jun 4, 2025

Closes #97

The contains() method in IPv4CidrRange and IPv6CidrRange now correctly handles being passed an IPv4 or IPv6 instance directly. Previously, it only worked correctly if passed another range instance, causing a TypeError when a single IP address was provided.

This change modifies AbstractIPRange.contains() to check the type of the argument. If it's an AbstractIPNum (i.e., a single IP address), it compares the IP's value against the range's start and end values. Otherwise, it uses the existing logic for comparing two ranges.

google-labs-jules bot and others added 4 commits June 4, 2025 01:20
The contains() method in IPv4CidrRange and IPv6CidrRange now correctly
handles being passed an IPv4 or IPv6 instance directly. Previously, it
only worked correctly if passed another range instance, causing a
TypeError when a single IP address was provided.

This change modifies AbstractIPRange.contains() to check the type of the
argument. If it's an AbstractIPNum (i.e., a single IP address), it
compares the IP's value against the range's start and end values.
Otherwise, it uses the existing logic for comparing two ranges.

I added unit tests for both IPv4 and IPv6 to verify that an IP address
can be correctly checked if it's contained within a CIDR range,
including edge cases.

Also, I updated the 'ipnum-build' script in package.json to include
NODE_OPTIONS=--openssl-legacy-provider to resolve a local build issue
with Webpack related to OpenSSL provider errors.
@dadepo dadepo merged commit aa952aa into master Jun 8, 2025
2 checks passed
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.

Check if an address lies within a range?

1 participant