-
Notifications
You must be signed in to change notification settings - Fork 6
output hex if user input is hex #20
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -40,15 +40,17 @@ function sequentialNumberGenerate() { | |||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| let result = start; | ||||||||||||||||||||||||||||||||||||||||
| let isHex = start.startsWith('0x'); | ||||||||||||||||||||||||||||||||||||||||
| let result = isHex ? parseInt(start, 16) : parseInt(start); | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
| let result = isHex ? parseInt(start, 16) : parseInt(start); | |
| let result = isHex ? parseInt(start, 16) : parseInt(start, 10); |
Copilot
AI
Jul 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using eval for arithmetic operations can introduce security risks and performance overhead. Consider replacing it with direct arithmetic based on operator (e.g., a switch statement).
| result = eval(result + operator + parseInt(step)); | |
| switch (operator) { | |
| case '+': | |
| result += parseInt(step); | |
| break; | |
| case '-': | |
| result -= parseInt(step); | |
| break; | |
| case '*': | |
| result *= parseInt(step); | |
| break; | |
| case '/': | |
| result /= parseInt(step); | |
| break; | |
| default: | |
| throw new Error('Unsupported operator: ' + operator); | |
| } |
Copilot
AI
Jul 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also specify a radix when calling parseInt(step) (e.g., parseInt(step, 10)) to prevent unintended parsing behavior.
| result = eval(result + operator + parseInt(step)); | |
| result = eval(result + operator + parseInt(step, 10)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only checks for a lowercase '0x' prefix; consider normalizing the input (e.g.,
start.toLowerCase().startsWith('0x')) to also support uppercase '0X'.