Skip to content

Commit

Permalink
Merge pull request #1958 from balena-io/check-int
Browse files Browse the repository at this point in the history
Only accept fully valid ints in `checkInt`
  • Loading branch information
Page- authored Feb 17, 2025
2 parents f89ca08 + 481ad11 commit ebe52ca
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export const checkInt = (num?: string): number | false => {
if (num == null) {
return false;
}
// If the string contains non-integer characters then it's not a valid integer, even if `parseInt` might turn it into one
if (!/^-?[0-9]+$/.test(num)) {
return false;
}
const n = parseInt(num, 10);
if (Number.isNaN(n)) {
return false;
Expand Down

0 comments on commit ebe52ca

Please sign in to comment.