Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix potential undefined issue with IP extraction in the ips function #33

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Budalebah
Copy link

In the current implementation, the ips(request) function can potentially return undefined, which leads to issues when accessing ip[0]. This would result in unintended behavior if ips(request) does not return an array, as the ip[0] expression would then return the first character of the fallback string "127.0.0.1".

To address this, I've updated the code to safely access the first element of the array returned by ips(request) using optional chaining (?.[0]). This ensures that if ips(request) returns undefined or an empty array, the default value "127.0.0.1" is correctly assigned.

Changes:

Replaced const ip = ips(request) ?? "127.0.0.1"; with const ip = ips(request)?.[0] ?? "127.0.0.1"; to prevent potential errors and ensure proper fallback behavior.
Benefits:

This change eliminates the risk of unexpected behavior if ips(request) returns undefined.
Ensures that ip[0] correctly retrieves the IP address or falls back to "127.0.0.1" as intended.

Copy link

vercel bot commented Aug 13, 2024

@Budalebah is attempting to deploy a commit to the Movement Labs Team on Vercel.

A member of the Team first needs to authorize it.

@Budalebah
Copy link
Author

just an idea ..

@Primata Primata closed this Oct 11, 2024
@Primata Primata reopened this Oct 11, 2024
@Budalebah
Copy link
Author

Hello @0xPrimata i was waiting for a few PRs since 2 months, can we finalize them pls 🙏🙏🙏

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.

2 participants