From b34a33581ca03bf29f097bd5381824537d33aa33 Mon Sep 17 00:00:00 2001 From: Anas Shakil Date: Thu, 25 Apr 2024 14:58:05 +0500 Subject: [PATCH] fix(isPort): Invalid leading zeros (#2208) --- src/lib/isInt.js | 5 +---- src/lib/isPort.js | 2 +- test/validators.test.js | 1 + 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/lib/isInt.js b/src/lib/isInt.js index 8047a6969..edd67f75a 100644 --- a/src/lib/isInt.js +++ b/src/lib/isInt.js @@ -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); diff --git a/src/lib/isPort.js b/src/lib/isPort.js index 0b316b78c..0a9ddce1d 100644 --- a/src/lib/isPort.js +++ b/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 }); } diff --git a/test/validators.test.js b/test/validators.test.js index efb745284..a05548335 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -2892,6 +2892,7 @@ describe('Validators', () => { '', '-1', '65536', + '0080', ], }); });