Skip to content

Commit b34a335

Browse files
authored
fix(isPort): Invalid leading zeros (#2208)
1 parent edb6b1c commit b34a335

3 files changed

Lines changed: 3 additions & 5 deletions

File tree

src/lib/isInt.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ export default function isInt(str, options) {
99

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

1714
// Check min/max/lt/gt
1815
let minCheckPassed = (!options.hasOwnProperty('min') || str >= options.min);

src/lib/isPort.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import isInt from './isInt';
22

33
export default function isPort(str) {
4-
return isInt(str, { min: 0, max: 65535 });
4+
return isInt(str, { allow_leading_zeroes: false, min: 0, max: 65535 });
55
}

test/validators.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2892,6 +2892,7 @@ describe('Validators', () => {
28922892
'',
28932893
'-1',
28942894
'65536',
2895+
'0080',
28952896
],
28962897
});
28972898
});

0 commit comments

Comments
 (0)