Skip to content

Commit

Permalink
fix(isPort): Invalid leading zeros (#2208)
Browse files Browse the repository at this point in the history
  • Loading branch information
anasshakil committed Apr 25, 2024
1 parent edb6b1c commit b34a335
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
5 changes: 1 addition & 4 deletions src/lib/isInt.js
Expand Up @@ -9,10 +9,7 @@ export default function isInt(str, options) {

// Get the regex to use for testing, based on whether
// leading zeroes are allowed or not.
let regex = (
options.hasOwnProperty('allow_leading_zeroes') && !options.allow_leading_zeroes ?
int : intLeadingZeroes
);
const regex = options.allow_leading_zeroes === false ? int : intLeadingZeroes;

// Check min/max/lt/gt
let minCheckPassed = (!options.hasOwnProperty('min') || str >= options.min);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/isPort.js
@@ -1,5 +1,5 @@
import isInt from './isInt';

export default function isPort(str) {
return isInt(str, { min: 0, max: 65535 });
return isInt(str, { allow_leading_zeroes: false, min: 0, max: 65535 });
}
1 change: 1 addition & 0 deletions test/validators.test.js
Expand Up @@ -2892,6 +2892,7 @@ describe('Validators', () => {
'',
'-1',
'65536',
'0080',
],
});
});
Expand Down

0 comments on commit b34a335

Please sign in to comment.