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: Fix incorrect type check in byteArrayFormat function #546

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

Conversation

0xsimka
Copy link
Contributor

@0xsimka 0xsimka commented Dec 22, 2024

Description

Hello!

While working with the byteArrayFormat function, I noticed an issue with the validation logic for array elements. The original condition:

if (!(o[i] instanceof Number && o[i] >= 0 && o[i] <= 255))

...always fails for valid numbers because instanceof Number checks for the Number object type, not for primitive numbers. Since numbers in JavaScript are typically primitives, this condition doesn't behave as intended.

I've updated the check to use typeof instead, which works correctly for primitive numbers:

if (typeof o[i] !== "number" || o[i] < 0 || o[i] > 255)

This fix ensures that the function correctly validates the elements of the array.

Type of Change

  • New Page
  • Page update/improvement
  • Fix typo/grammar
  • Restructure/reorganize content
  • Update links/references
  • Other (please describe):

Checklist

  • I ran pre-commit run --all-files to check for linting errors
  • I have reviewed my changes for clarity and accuracy
  • All links are valid and working
  • Images (if any) are properly formatted and include alt text
  • Code examples (if any) are complete and functional
  • Content follows the established style guide
  • Changes are properly formatted in Markdown
  • Preview renders correctly in development environment

Contributor Information

Copy link

vercel bot commented Dec 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
documentation ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 22, 2024 0:24am

Copy link

vercel bot commented Dec 22, 2024

@0xsimka is attempting to deploy a commit to the Pyth Network Team on Vercel.

A member of the Team first needs to authorize it.

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