From 6bcbf19dbbd945268f75602c984530aada030506 Mon Sep 17 00:00:00 2001 From: lqzhgood Date: Thu, 7 Feb 2019 23:47:39 +0800 Subject: [PATCH] The value must be a string fix #131 --- lib/clean-host.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/clean-host.js b/lib/clean-host.js index 4a20697..2b69297 100644 --- a/lib/clean-host.js +++ b/lib/clean-host.js @@ -66,6 +66,9 @@ function checkLowerCaseNeeded(value) { module.exports = function extractHostname(value) { + if (!value || typeof value !== 'string') { + return null; + } // First check if `value` is already a valid hostname. if (isValid(value)) { return trimTrailingDots(value); @@ -73,10 +76,6 @@ module.exports = function extractHostname(value) { var url = value; - if (typeof url !== 'string') { - url = '' + url; - } - var needsTrimming = checkTrimmingNeeded(url); if (needsTrimming) { url = url.trim();