Skip to content

fix: validate parseInt result in getTokenFromUrl - #558

Open
dajiaohuang wants to merge 8 commits into
framesjs:mainfrom
dajiaohuang:fix/validate-parseInt-in-getTokenFromUrl
Open

fix: validate parseInt result in getTokenFromUrl#558
dajiaohuang wants to merge 8 commits into
framesjs:mainfrom
dajiaohuang:fix/validate-parseInt-in-getTokenFromUrl

Conversation

@dajiaohuang

Copy link
Copy Markdown

Summary

修复 getTokenFromUrl 函数中 parseInt 可能返回 NaN 的问题。

问题

如果 chainId 不是有效的数字字符串(如 "abc"),parseInt(chainId) 会返回 NaN,但这个 NaN 会被直接返回而没有任何错误提示。

代码变更

// Before
chainId: parseInt(chainId),

// After
const parsedChainId = parseInt(chainId);

if (Number.isNaN(parsedChainId)) {
  throw new Error("Invalid token URL: chainId is not a valid number");
}

return {
  ...
  chainId: parsedChainId,
  ...
};

Fix

现在会验证 parseInt 的结果,如果返回 NaN 则抛出错误。

- Remove redundant else branch that was overwriting acc[type] with the same value
- Fix mutable default argument by creating requestOptions object fresh each time
- Properly merge user-provided hubRequestOptions with default api_key header
Create fresh requestOptions object each time to avoid shared mutable default.
Properly merge user-provided hubRequestOptions with default api_key header.
Create fresh requestOptions object each time to avoid shared mutable default.
Properly merge user-provided hubRequestOptions with default api_key header.
- Fix mutable default argument by using empty object as default
- Add missing api_key header when using default hub URL
When using the default hub URL, user-provided hubRequestOptions
(like cache, credentials, etc.) were being completely lost.
Now properly merges user options with the default api_key header.
parseInt could return NaN for invalid chainId strings without
any indication of error. Now validates and throws an error if
chainId is not a valid number.
@vercel

vercel Bot commented Sep 2, 2026

Copy link
Copy Markdown

@dajiaohuang is attempting to deploy a commit to the Discove Team on Vercel.

A member of the Team first needs to authorize it.

@vercel vercel Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Additional Suggestion:

Missing first-seen assignment in the valuesByType reduce causes all returned user data fields to be undefined

Fix on Vercel

fallbackToCustodyAddress = true,
hubHttpUrl = DEFAULT_HUB_API_URL,
hubRequestOptions = {
headers: {

@vercel vercel Bot Sep 2, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Default public hub api_key is applied unconditionally and (in three of four files) overwrites a caller's own api_key, breaking authentication against custom/private hubs.

Fix on Vercel

@dajiaohuang

Copy link
Copy Markdown
Author

Addressed the current review feedback in the latest commit. The user-data reducer now stores the first value for each type and replaces it only when a newer timestamp is seen, so first-seen fields are no longer lost. Validation: git diff --check passed. The local checkout has no Yarn binary/dependencies, so the package test suite could not run here.

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.

1 participant