From 259454ef33aabdfd586d89feac594b64dfef3e4e Mon Sep 17 00:00:00 2001 From: ray-1337 <33544674+ray-1337@users.noreply.github.com> Date: Tue, 12 Apr 2022 00:38:15 +0200 Subject: [PATCH] validate if port param existed --- src/methods/allow.js | 8 +++++--- src/methods/deny.js | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/methods/allow.js b/src/methods/allow.js index d195c24..403ba6e 100644 --- a/src/methods/allow.js +++ b/src/methods/allow.js @@ -59,9 +59,11 @@ module.exports.address = async function (address, port, protocol) { if (!checkAddress) return false; // port validation - if (typeof port !== "number") throw new Error("The port must be type of number."); - let checkPort = util.checkAppropriatePort(port); - if (!checkPort) return false; + if (port) { + if (typeof port !== "number") throw new Error("The port must be type of number."); + let checkPort = util.checkAppropriatePort(port); + if (!checkPort) return false; + }; // protocol (tcp/udp) validation if (protocol) { diff --git a/src/methods/deny.js b/src/methods/deny.js index 219c61c..3cee983 100644 --- a/src/methods/deny.js +++ b/src/methods/deny.js @@ -59,9 +59,11 @@ module.exports.address = async function (address, port, protocol) { if (!checkAddress) return false; // port validation - if (typeof port !== "number") throw new Error("The port must be type of number."); - let checkPort = util.checkAppropriatePort(port); - if (!checkPort) return false; + if (port) { + if (typeof port !== "number") throw new Error("The port must be type of number."); + let checkPort = util.checkAppropriatePort(port); + if (!checkPort) return false; + }; // protocol (tcp/udp) validation if (protocol) {