Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

fix: ethers_providers::is_local_endpoint with rust matching pattern on URL::parse #2351

Merged
merged 6 commits into from
Apr 24, 2023

Conversation

loocapro
Copy link
Contributor

@loocapro loocapro commented Apr 14, 2023

Related to #2346 and foundry issue #4658

Motivation

ethers_providers::is_local_endpoint function would only work with localhost and 127.0.0.1 strings.

Solution

From substring matching to rust pattern matching based on URL::parse result.

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm,

would appreciate a smol sanity test for this

@loocapro
Copy link
Contributor Author

lgtm,

would appreciate a smol sanity test for this

You want one more unit test? I thought doctest were enough?

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah right,

lgtm

if let Some(host) = url.host() {
match host {
Host::Domain("localhost") => return true,
Host::Ipv4(ipv4) => return ipv4 == Ipv4Addr::LOCALHOST || ipv4.is_link_local(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about ipv4.is_private() and ipv4.is_loopback()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 1459 to 1460
// skipping IPV6 check
_ => return false,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to include the same for Ipv6Addr? (ipv6.is_loopback())

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point loopback is available for both variants

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@loocapro
Copy link
Contributor Author

@mattsse @DaniPopes all good?

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@prestwich prestwich merged commit 81ad822 into gakonst:master Apr 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants