Skip to content

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

Open
Budalebah wants to merge 1 commit into
movementlabsxyz:mainfrom
Budalebah:main
Open

Fix potential undefined issue with IP extraction in the ips function#33
Budalebah wants to merge 1 commit into
movementlabsxyz:mainfrom
Budalebah:main

Conversation

@Budalebah
Copy link
Copy Markdown

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.

@vercel
Copy link
Copy Markdown

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
Copy Markdown
Author

just an idea ..

@Primata Primata closed this Oct 11, 2024
@Primata Primata reopened this Oct 11, 2024
@Budalebah
Copy link
Copy Markdown
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