From bb9fef0bf6e167114a87adc17d5cd078f0c77299 Mon Sep 17 00:00:00 2001 From: xiaoyao-666-coder <251972984+xiaoyao-666-coder@users.noreply.github.com> Date: Sun, 8 Nov 2026 10:29:36 +0800 Subject: [PATCH] fix(isPort): reject signed port numbers --- src/lib/isPort.js | 3 ++- test/validators.test.js | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/lib/isPort.js b/src/lib/isPort.js index 0a9ddce1d..18e0c4fe9 100644 --- a/src/lib/isPort.js +++ b/src/lib/isPort.js @@ -1,5 +1,6 @@ import isInt from './isInt'; export default function isPort(str) { - return isInt(str, { allow_leading_zeroes: false, min: 0, max: 65535 }); + return isInt(str, { allow_leading_zeroes: false, min: 0, max: 65535 }) && + !/^[-+]/.test(str); } diff --git a/test/validators.test.js b/test/validators.test.js index 98d2a12ff..f3596fd49 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -3231,6 +3231,19 @@ describe('Validators', () => { }); }); + it('should reject signed port numbers', () => { + test({ + validator: 'isPort', + invalid: [ + '+0', + '-0', + '+80', + '+443', + '+65535', + ], + }); + }); + it('should validate passport number', () => { test({ validator: 'isPassportNumber',